O'Reilly logo

Microsoft® .NET Compact Framework (Core Reference) by Mark Sutton, Rory MacLoed, Robert Burbidge, Stephen Wheelwright, Andy Wigley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the File, Path, and Directory Classes

The File class provides static members for creating, copying, moving, and deleting files. The FileInfo class provides the same features but as instance members of the class.

Using the File Class to Create a File

The Create static method of the File class creates or overwrites a file and returns a FileStream object. You can then read the file at the byte level using the returned FileStream, or you can read the file at the character level using a StreamReader. The following code creates a file called myFile.txt and then creates a StreamWriter object based on the FileStream object returned by the call to File.Create. If an error arises, such as the file already being open, an exception is thrown.

try {      ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required