VB.NET is commonly used

xiaoxiao2021-03-06  38

1 Get the current login user name in the Windows program, and the web program is obtained with SystemInformation.userName.

2

.NET access file

Although the preferred data access is through a background database or XML, you rarely have the opportunity to choose the way data is accessible. In general, the company will inevitably be rich in LEGACY DATA, so you must be able to access a variety of different data sources. Text file is one of the ordinary ways. The long group in the .NET class provides the needs of the system.io space name. Let us now see how to use this spatial name to access the file content. Streams

The .NET framework uses the flow to process various input types. A stream represents the data flow of input or output to a data source, the data source is a backend (file, socket, etc.) of a stream.

The System.io space name contains an abstract basic stream class. This is defined in a byte manner to read or write the original data. You don't have to handle raw data, but you have to handle the created storage format, such as file or network sockets.

System.io space names include many classes that extends the Stream class to handle a variety of different storage methods. These classes include the following:

Directory: Provides processing methods related to paths, such as establish, copy, move, and delete. FILE: Provides processing methods related to file operations, such as establishing, establishing, moving, and deleting. FILESTREAM: File operations for synchronous and asynchronous. MemoryStream: Processes data stored in memory. StringReader: Access data related to string (using the TextReader class). StringWriter: Establish data related to String (using the textwriter class). TextReader: Used to read a sequence character. TEXTWRITER: Used to write a sequence character. Examples of the SYSTEM.IO space name, you can see the flexibility of the containment. One of these classes is that a stream serves a class as a front desk, which is likely to perform excess processing on the first stream. As with the file operation, these methods are applied to the encryption or buffer processing. Since we have established the basic knowledge of .NET stream, let us learn more about the use of flows to handle data files. The File class that works in the text file mode for the SYSTEM.IO space name provides the required feature for text files. The following VB.NET Source Codes illustrates it easy to use, this code snippet is the content of a text file located in the local hard disk: DIM SR AS StreamReaderdim FileContents as stringsr = file.opentext ("c: //test.txt) ") FileContents = Sr.ReadToend () console.writeline (filecontents) sr.close () Similar code in C # is quite simple: streamreadersr = null; string filecontents = null; sr = file.opentext (" c: // PRODINFO.TXT "); filecontents = sr.readToend (); console.writeline (filecontent); sr.close (); About this example, there are several places worth noting. First, you must include the system.io space name to ensure that the code can run according to the plan. At the same time, the StreamReader class is used as a front desk of the FLIE class. This code example uses the READTOEEND method of the StreamReader class to read the full content of the file, in addition to this, the following other methods are included to access the file: readline: Read a line at a certain time. READ: Use fixed points and length to read the file content. Readblock: Reads the data to the buffer. PEEK: Reads the next character. You can use the Readline method to read the contents of the file, which can change the read mode of the previous example. The following C # code implements this requirement: streamreadersr = null; string online = null; sr = file.opentext ("c: //test.txt"); oneLine = sr.readline (); while (OneLine! = Null) {Console.WriteLine (OneLine); OneLine = Sr.Readline ();} sr.close (); Code uses the While loop to read the entire file content in a way at some point.

转载请注明原文地址:https://www.9cbs.com/read-61954.html

New Post(0)