Presentation is loading. Please wait.

Presentation is loading. Please wait.

File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization.

Similar presentations


Presentation on theme: "File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization."— Presentation transcript:

1 File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization is called a sequential file. The most common type of organization is called a sequential file..net framework views each file as a sequential stream of bytes.net framework views each file as a sequential stream of bytes Each file ends with either an end-of- file marker or at a specific byte number Each file ends with either an end-of- file marker or at a specific byte number

2 Class stream Abstract class Stream (namespace System::IO) provides functionality for representing streams as bytes Abstract class Stream (namespace System::IO) provides functionality for representing streams as bytes Class FileStream, MemoryStream and BufferedStream inherit from class Stream Class FileStream, MemoryStream and BufferedStream inherit from class Stream FileStream: read from and write data to sequential- access and random-access file FileStream: read from and write data to sequential- access and random-access file MemoryStream: enables transfers of data directly to and from memory (faster) MemoryStream: enables transfers of data directly to and from memory (faster) BufferedStream: use buffering to transfer data to or from a stream. (performance enhancement technique, in which each I/O operation is directed to a region in memory, called a buffer. The actual transfer is performed in one large physical output operation each time the buffer fills BufferedStream: use buffering to transfer data to or from a stream. (performance enhancement technique, in which each I/O operation is directed to a region in memory, called a buffer. The actual transfer is performed in one large physical output operation each time the buffer fills

3 Class File Class File is provided for maintaining files Class File is provided for maintaining files Class File cannot read from or write to files directly Class File cannot read from or write to files directly Separator character /. In.net, both / and \ are valid Separator character /. In.net, both / and \ are valid However, when use \ in string, one must use \\ However, when use \ in string, one must use \\ For example, C:\\CS603/project For example, C:\\CS603/project

4 Static methods Class File contain only static methods Class File contain only static methods You cannot instantiate objects of type File You cannot instantiate objects of type File Copy: copies a file to a new file Copy: copies a file to a new file Create: creates a file and return its associated FileStream Create: creates a file and return its associated FileStream Delete: deletes the specified file Delete: deletes the specified file Exists: return true if the specified file exists; otherwise, it returns false Exists: return true if the specified file exists; otherwise, it returns false GetCreationTime: return DateTime object representing the time that file was created GetCreationTime: return DateTime object representing the time that file was created GetLastAccessTime: GetLastAccessTime: GetLastWriteTime: GetLastWriteTime: Move: moves the specified file to a specified location Move: moves the specified file to a specified location

5 Static methods- continued Open: return FileStream associated with the specified file Open: return FileStream associated with the specified file OpenRead: returns a read-only FileStream associated with the specified file OpenRead: returns a read-only FileStream associated with the specified file OpenWrite: return a read/write FileStream associated with the specified file OpenWrite: return a read/write FileStream associated with the specified file OpenText: returns a StreamReader associated with the specified file OpenText: returns a StreamReader associated with the specified file

6 Class Directory Class Directory is provided for manipulating directories. Class Directory is provided for manipulating directories. It provides capabilities for manipulating and iteration directories It provides capabilities for manipulating and iteration directories Static methods Static methods CreateDirectory: creates a directory and returns its associated DirectoryInfo. CreateDirectory: creates a directory and returns its associated DirectoryInfo. The DirectoryInfo object returned by method CreateDirectory contains information about a directory. The DirectoryInfo object returned by method CreateDirectory contains information about a directory.

7 Other static methods Delete: deletes the specified directory Delete: deletes the specified directory Exists: return true if the specified directory exists; otherwise, it returns false Exists: return true if the specified directory exists; otherwise, it returns false GetLastWriteTime: return a DataTime object representing the time that the directory was last modified GetLastWriteTime: return a DataTime object representing the time that the directory was last modified GetDirectories: return a String *array representing the names of the directories in the specified directory GetDirectories: return a String *array representing the names of the directories in the specified directory GetFiles: returns a String * array representing the names of the files in the specified directory GetFiles: returns a String * array representing the names of the files in the specified directory GetCreationTime GetCreationTime


Download ppt "File and Streams There are many ways of organizing records in a file. There are many ways of organizing records in a file. The most common type of organization."

Similar presentations


Ads by Google