22

File System Data

In this chapter, you learn how to read and write files, an essential aspect of many .NET applications. You touch on the major classes used to create, read from, and write to files, and the supporting classes used to manipulate the file system from C# code. Although you won't cover all of the classes in detail, this chapter will go into enough depth to give you a good idea of the concepts and fundamentals.

Files can be a great way to store data between instances of your application, or they can be used to transfer data between applications. User and application configuration settings can be stored to be retrieved the next time your application is run. Delimited text files, such as comma-separated files, are used by many legacy systems, and to interoperate with such systems you will need to know how to work with delimited data. As you will see, the .NET Framework provides you with the tools to use files effectively in your applications.

By the end of this chapter, you will have learned:

  • What a stream is and how .NET uses stream classes to access files
  • How to use the File object to manipulate the file structure
  • How to write to a file
  • How to read from a file
  • How to read and write formatted data from and to files
  • How to read and write compressed files
  • How to serialize and deserialize objects
  • How to monitor files and directories for changes

Streams

All input and output in the .NET Framework involves the use of streams. A stream is an abstract representation of a ...

Get Beginning Visual C#® 2005 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.