C# System.IO Namespace – File Handling Tutorial

system-io
In this chapter you will learn

  • What is System.IO Namespace?
  • Classes, Methods and Enumeration of System.IO Namespace?
  • Programming Examples

System.IO Namespace is a collection of classes, methods, enumeration and types that is responsible for reading and writing files and data streams. All the File Handling operations require System.IO namespace.

Classes

ClassDescription
BinaryReaderReads primitive data types as binary values in a specific encoding.
BinaryWriterWrites primitive types in binary to a stream and supports writing strings in a specific encoding.
BufferedStreamAdds a buffering layer to read and write operations on another stream. This class cannot be inherited.
DirectoryExposes static methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
To browse the .NET Framework source code for this type, see the Reference Source.
DirectoryInfoExposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
To browse the .NET Framework source code for this type, see the Reference Source.
DirectoryNotFoundExceptionThe exception that is thrown when part of a file or directory cannot be found.
DriveInfoProvides access to information on a drive.
DriveNotFoundExceptionThe exception that is thrown when trying to access a drive or share that is not available.



  • EndOfStreamExceptionThe exception that is thrown when reading is attempted past the end of a stream.
    ErrorEventArgsProvides data for the FileSystemWatcher.Error event.
    FileProvides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of FileStream objects.
    To browse the .NET Framework source code for this type, see the Reference Source.
    FileFormatExceptionThe exception that is thrown when an input file or a data stream that is supposed to conform to a certain file format specification is malformed.
    FileInfoProvides properties and instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. This class cannot be inherited.
    To browse the .NET Framework source code for this type, see the Reference Source.
    FileLoadExceptionThe exception that is thrown when a managed assembly is found but cannot be loaded.
    FileNotFoundExceptionThe exception that is thrown when an attempt to access a file that does not exist on disk fails.
    FileStreamProvides a Stream for a file, supporting both synchronous and asynchronous read and write operations.
    To browse the .NET Framework source code for this type, see the Reference Source.
    FileSystemEventArgsProvides data for the directory events: Changed, Created, Deleted.
    FileSystemInfoProvides the base class for both FileInfo and DirectoryInfo objects.
    FileSystemWatcherListens to the file system change notifications and raises events when a directory, or file in a directory, changes.
    To browse the .NET Framework source code for this type, see the Reference Source.
    InternalBufferOverflowExceptionThe exception thrown when the internal buffer overflows.
    InvalidDataExceptionThe exception that is thrown when a data stream is in an invalid format.
    IODescriptionAttributeSets the description visual designers can display when referencing an event, extender, or property.
    IOExceptionThe exception that is thrown when an I/O error occurs.
    MemoryStreamCreates a stream whose backing store is memory.
    To browse the .NET Framework source code for this type, see the Reference Source.
    PathPerforms operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.
    To browse the .NET Framework source code for this type, see the Reference Source.
    PathTooLongExceptionThe exception that is thrown when a path or file name is longer than the system-defined maximum length.
    PipeExceptionThrown when an error occurs within a named pipe.
    RenamedEventArgsProvides data for the Renamed event.
    StreamProvides a generic view of a sequence of bytes. This is an abstract class.
    To browse the .NET Framework source code for this type, see the Reference Source.
    StreamReaderImplements a TextReader that reads characters from a byte stream in a particular encoding.
    To browse the .NET Framework source code for this type, see the Reference Source.
    StreamWriterImplements a TextWriter for writing characters to a stream in a particular encoding.
    To browse the .NET Framework source code for this type, see the Reference Source.
    StringReaderImplements a TextReader that reads from a string.
    StringWriterImplements a TextWriter for writing information to a string. The information is stored in an underlyingStringBuilder.
    TextReaderRepresents a reader that can read a sequential series of characters.
    TextWriterRepresents a writer that can write a sequential series of characters. This class is abstract.
    UnmanagedMemoryAccessorProvides random access to unmanaged blocks of memory from managed code.
    UnmanagedMemoryStreamProvides access to unmanaged blocks of memory from managed code.

    Enumerations

    EnumerationDescription
    DriveTypeDefines constants for drive types, including CDRom, Fixed, Network, NoRootDirectory, Ram, Removable, and Unknown.
    FileAccessDefines constants for read, write, or read/write access to a file.
    FileAttributesProvides attributes for files and directories.
    FileModeSpecifies how the operating system should open a file.
    FileOptionsRepresents advanced options for creating a FileStream object.
    FileShareContains constants for controlling the kind of access other FileStream objects can have to the same file.
    HandleInheritabilitySpecifies whether the underlying handle is inheritable by child processes.
    NotifyFiltersSpecifies changes to watch for in a file or folder.
    SearchOptionSpecifies whether to search the current directory, or the current directory and all subdirectories.
    SeekOriginSpecifies the position in a stream to use for seeking.
    WatcherChangeTypesChanges that might occur to a file or directory.

    Summary

    In this chapter you learned about System.IO Namespace and its classes. In the next chapter you will learn how to read files using FileStream.


    Leave a Reply

    Your email address will not be published. Required fields are marked *