Facilitates reading from a standard text file.
Accessing files is done under the context of the user that the application or service is running under. This can cause some file permissions/access rights issues if the file does not allow access to that user.
Constructors
none
Instance Properties
EndOfFile
Gets a value that indicates whether the current position is at the end of the file.
Type:
BooleanExample:
eof = file.EndOfStream;
Static Methods
ReadAllText
Opens a file, reads all the text from the file, then closes it.
Syntax:Parameters:path: The file to append the specified string to.
Return ValueA string containing all lines of the file.
Example:
s = TextFileReader.ReadAllText("c:\myfiles\names.txt");
OpenText
Opens an existing UTF-8 file for reading.
Syntax:Parameters:path: The file to be opened for reading.
Return ValueExample:
file = TextFileReader.OpenText("c:\myfiles\names.txt");
Instance Methods
ReadLine
Reads a line of characters from the current file and returns the data as a string.
Syntax:Return ValueThe next line from the file, or a empty string if the end of the file is reached.
Example:
file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.ReadLine();
ReadToEnd
Reads the file from the current position to the end of the file.
Syntax:Return ValueThe next line from the file, or a empty string if the end of the file is reached.
Example:
file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.ReadToEnd();
Peek
Reads the the next available character but does not consume it.
Syntax:Return ValueThe next line from the file, or a empty string if the end of the file is reached.
Example:
file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.Peek();
Close
Closes the current file.
Syntax:Example:
file = TextFileReader.OpenText("c:\myfiles\names.txt");
s = file.Peek();
file.Close();
See Also