Skip to main content

System.IO Namesapce in C#

 System.IO Namesapce in C#

file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream.

The stream is basically the sequence of bytes passing through the communication path. There are two main streams: the input stream and the output stream. The input stream is used for reading data from file (read operation) and the output stream is used for writing into the file (write operation).

From the above definition of file, the C# provides a namespace that enable us to manipulate file in C# called System.IO.

 System.IO is a namespace and it contains a standard IO (input/output) types such as classes, structures, enumerations, and delegates to perform a read/write operations on different sources like file, memory, network, etc.

 System.IO Classes

The table below shows different type of classes that exists in System.IO namespace to perform different operations like creating files, writing to files, reading from files, etc.

 

Class

Description

BinaryReader

This class is useful to read primitive data types from a binary stream

BinaryWriter

It is useful to write primitive types in binary format

BufferedStream

This class is useful to read and write bytes from other streams

Directory

This class provides methods to manipulate the directories and subdirectories such as Create and Move etc

File

The class provides methods to manipulate files like Create, Copy, delete, move etc

FileStream

It is useful to read/write bytes from/to files

MemoryStream

The class is use to read or write bytes that are store in memory

Path

It is use to perform operations on directory path information

Stream

This class is an abstract class and it will provide a methods to transfer bytes to the source.

StreamReader

This class is useful to read a characters from stream by converting bytes into characters using an encoded value.

StreamWriter

This class is useful to write a characters to stream by converting characters into bytes using an encoded value.

StringReader

This class is useful to read from a string.

StringWriter         

This class is useful to write information to string.

TextReader

This class is useful to read a sequential series of characters.

TextWriter 

This class is abstract and it is useful to write a sequential series of characters.

System.IO Structures

The table below shows the different type of structures which exists in System.IO namespace.

 

Structure

Description

WaitForChangedResult

This structure will contain information on the changes that occurred.

System.IO Enumerations

The table below shows the different type of enumerations which exists in System.IO namespace.

 

Enumeration

Description

DriveType 

This will define constants for drive types.

FileAccess  

It defines constants for reading, write, or read/write access to a file.

FileAttributes

It provides attributes for files and directories.

FileMode   

It specifies how an operating system will open the file.

FileOptions

It provides an advanced options for creating a filestream object.

FileShare   

It contains constants to control the access of filestream objects.

HandleInheritability

It is useful to specify whether the underlying handle is inheritable by child processes.

NotifyFilters        

It specifies the changes to watch for in a file or folder.

SearchOption      

It will specifies whether to search the current directory or the current directory and all subdirectories.

SeekOrigin 

It will specifies the position in a stream to use for seeking.

WatcherChangeTypes

It will specifies the changes that might occur to a file or directory.

System.IO Delegates

The table below shows the different type of delegates which exists in System.IO namespace.

 

Delegate

Description

ErrorEventHandler       

This will represent a method that will handle the error event of a FileSystemWatcher object.

FileSystemEventHandler

It will represent a method that will handle the changed, created, or deleted event of a FileSystemWatcher class.

RenamedEventHandler 

It will represent a method that will handle the renamed event of a FileSystemWatcher class.

 References

1.    TutorialPoints

2.    Tutlane

Comments

Popular posts from this blog

The String.Join Method in C# Explained

The String.Join Method in C#   The string.Join concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member. Overloads of string.Join Method Description Join(Char, Object[]) Concatenates the string representations of an array of objects, using the specified separator between each member. Join(Char, String[]) Concatenates an array of strings, using the specified separator between each member. Join(String, IEnumerable<String>) Concatenates the members of a constructed IEnumerable<T> collection of type String, using the specified separator between each member. Join(String, Object[]) Concatenates the elements of an object array, using the specified separator between each element. Join(String, String[]) Concatenates all the elements of a string array, usi...

Most Popular Programming Languages in 2020

Most Popular Programming Languages in 2020 In this blog post, you will learn about the most popular programming languages in 2020 for creating the best web applications. Check its pros and cons. Analyzed by technostacks Not very long ago, just a few people were considered to be computer programmers, and the general public viewed them with awe. In this digital age that we are now living in, however, a large number of IT jobs need a solid grasp of one or more programming languages. Whether one wants to develop a mobile app or get a certification for having programming knowledge, or even to learn new skills, one needs to opt for the right programming language. Below mentioned eight most popular programming languages which are in demand for software development and web applications. This is the most used programming languages in 2019 and will be in 2020. For each, there is little information about the language, benefits and its complexity, as well as about its usage. One must...

HashTable in C# with Example

  HashTable in C# with Example Hashtable  is used to store a collection of key/value pairs of different  data types  and are organized based on the hash code of the key.   Generally, the hashtable object will contain buckets to store elements of the collection. The bucket here, is a virtual subgroup of elements within the hashtable and each bucket is associated with a hash code, which is generated based on the key of an element.   In C#, hashtable is same as a  dictionary  object but the only difference is that the  dictionary  object is used to store a key-value pair of same  data type  elements.   When compared with  dictionary  object, the hashtable will provide a lower performance because the hashtable elements are of object type so the boxing and unboxing process will occur when we are storing or retrieving values from the hashtable.   C# HashTable Declaration Hashtable is a non-generic type...