1 / 7

File and Streams

Learn how to organize records in a file using sequential organization. Explore the FileStream, MemoryStream, and BufferedStream classes for reading and writing data. Understand how to manipulate directories using the Directory class.

otaylor
Download Presentation

File and Streams

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File and Streams • There are many ways of organizing records in a file. • The most common type of organization is called a sequential file. • .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

  2. Class stream • Abstract class Stream (namespace System::IO) provides functionality for representing streams as bytes • Class FileStream, MemoryStream and BufferedStream inherit from class Stream • FileStream: read from and write data to sequential-access and random-access file • 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 is filled

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

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

  5. Static methods- continued • Open: return 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 • OpenText: returns a StreamReader associated with the specified file

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

  7. Other static methods • Delete: deletes the specified directory • 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 • GetDirectories: return 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

More Related