Chapter Five
Chapter Five
Chapter Five
Institute of Technology
• The input stream is used for reading data from file (read operation)
and the output stream is used for writing into the file (write
operation).
• C# I/O Classes: The System. IO namespace has various classes that are
used for performing numerous operations with files, such as creating
and deleting files, reading from or writing to a file, closing a file etc.
Cont..
• FileMode: The FileMode enumerator defines various methods for opening files.
The members of the FileMode enumerator are:
• Append: It opens an existing file and puts cursor at the end of file, or
creates the file, if the file does not exist.
• new file
Cont..
• File.Exists( ) method ensures specified text file does not already exis
• This will return true when file is found ,otherwise it will return false
Cont..
Cont..
• Press F5 to run the application and see a text file written on Your
desktop or see an error.
Reading text and lines
• The C# System.IO.File class library provides a ReadAllText() method
that can be used to read text from an existing file and assign its entire
contents to a string variable.