100 likes | 225 Views
Introduction. A File stores and maintains data called Persistent DataWhere a File is stored: second storage devices such as disks.When using a file, you need to load the file to computer memory.Create, upload and process data files in C
E N D
1. Files and Streams in C#
2. Introduction A File stores and maintains data called Persistent Data
Where a File is stored: second storage devices such as disks.
When using a file, you need to load the file to computer memory.
Create, upload and process data files in C#
3. Files and Streams The System.IO namespace includes stream classes such as StreamReader, StreamWriter and FileStream for file input and output.
These stream classes inherit from abstract classes TextReader, TextWriter and Stream, respectively.
Abstract class Stream provides functionality for representing streams as bytes.
Classes FileStream, MemoryStream and BufferedStream (all from namespace System.IO) inherit from class Stream.
Class FileStream can be used to write data to and read data from files.
4. Methods Related to File The following lists several of class File’s static methods for manipulating and determining information about files.
5. More Methods More Methods
6. Directory Class Class Directory provides capabilities for manipulating directories.
7. More Methods Related to Directory More static methods:
8. File Operation Open and Close: they are used before/after you want to read, write, and modify the file.
When open is called, the file is locked and loaded to memory and nobody else can access the file;
When close is called, the lock is released and the file is also released from memory.
9. How to Read File: Using StreamReader There are many ways you can read a file:
10. How to Read File: Using FileStream There are many ways you can read a file: