COMP 2150 Study Guide - Final Guide: Temporary File, Ole Db, Binary File
SchoolUniversity of Manitoba
Course CodeCOMP 2150
This preview shows half of the first page. to view the full 2 pages of the document.
Like the members of the File class, all members in the Directory class are public
static methods. The Directory class provides static methods for creating and
moving through directories and subdirectories.
.NET also includes DirectoryInfo and FileInfo classes.These classes are very similar to
their name counterparts, Directory and File.They differ in that the DirectoryInfo
and FileInfo classes both have instance methods instead of static members.They are direct
descendents of the FileSystemInfo class.
The FileInfo and DirectoryInfo classes add functionality beyond method members of
the File and Directory classes. They both have a number of public properties and, of
course, both offer a public constructor. Neither class can be inherited. If you plan to make
reference to and use a file or directory several times, you will want to consider instantiating
objects of one or both of these classes and use its instance methods.
C# uses file streams to deal with stored data. Streams represent a chunk of data and provide a
way to work with a sequence of bytes. Several abstract classes, including Stream,
TextWriter, and TextReader, are defined for dealing with files.These classes are defined
in the System.IO namespace.The stream classes provide generic methods for dealing with
input/output, and these methods reduce the need for providing specific details about how the
operating system actually accesses data from particular devices.
The StreamWriter and StreamReader classes make it easy to read or write data to and
from text files in C#.The StreamWriter class has implementations for Write( ) and
WriteLine( ) methods similar to the Console class methods. StreamReader includes
implementations of Read( ) and ReadLine( ).The simplest constructor for these classes
includes a single argument for the name of the file.The name may include the full path indicating
where the file is located or you may use the relative path to the file. Relative paths are
relative to the starting location of the project.
Constructing an object of the StreamWriter class using it as the second argument
enables you to append values onto the end of a file. The following statement opens the file
named info.txt, stored in the project subdirectory, so that records will be added onto the end
of the file:
fileOut = new StreamWriter(“../../info.txt”, true);
The StreamReader class was designed to enable lines of text to be read from a file. If
you do not specify a different type of encoding (coding representation), the characters read
are converted by default to strings of Unicode characters.
The BinaryWriter and BinaryReader classes are used for writing and readingda ta, rather than
character strings. The files created are readable by the computer but,
unlike the files created by the StreamWriter class, you cannot simply open and read
the contents of a binary file using Notepad.A program is needed to interpret the file contents.
You're Reading a Preview
Unlock to view full version