Mike Cat (Mikecat)
From: Old cat の Ide
I introduced File and Filestream, I introduced these object purposes under system.io space to explain how to make ASP.NET counters to make a film. Oh, continue to explain the StreamReader object below. The StreamReader object is the object that is most directly to the file and is one of the most important objects in reading and writing. Creating a StreamReader object Creating a StreamReader object You can use the File object's OpenText method or constructor of the StreamReader object.
OpenText method using File object
Dim Mikecatreader as StreamReader
Dim Mikecatfile As New File ("c: /mikecat.txt")
Mikecatreader = mikecatfile.opentext ()
Use the constructor of the StreamReader object
Dim Mikecatreader As New StreamReader ("C: /Mikecat.txt")
Main method of StreamReader object
StreamReader object implements read operations for files
(1) Close method
The Close method is the method that the StreamReader object must use. After using the StreamReader object, you must use the Close method to release the fileReader object operations and other system resources after using the StreamReader object. If you don't use a Close method, other processes will not be able to do anything.
SUB Close ()
(2) Read method
This method is used to read a character or a character set. When it is used to read a character, the function read () AS INTEGER reads a character, and the current position of the file stream moves a character.
The function read (buffer (), index, count) AS Integer parameter buffer () is a buffer for receiving reading characters, and the index parameter is the starting position of the read. [], Count parameters It is the maximum number of [b] [/ b] of reading characters. The return value is the actual number of characters read, and the return value is generally equal to the count value unless the end of the file is.
(3) Readline method
This method is used to read a row of data, and a row of data in the file is used as a carriage return symbol.
Function Readline () AS String
(4) READBLOCK method
This method is used to read data blocks
Function Readblock (Buffer (), INDEX, Count AS Integer
The READBLOCK method is basically similar to the read method.
(5) ReadToend method
This method is used to read all the data in the file.
Function readtoend () AS STRING
It should be noted that the string buffer that accepts the return value must be defined enough, otherwise it is easy to cause overflow.
Next time I introduced the introduction of the StreamWriter object. I hope everyone pays attention, I have been tired, I seem to get something, it is not easy. sweat!