Home » .Net

Introduction to file handling in C#

Learn: What is file handling in C#.Net? What are streams, type of streams, basic file operations and classes are used for file operations.

What is a file in C#?

File is a collection of data, which has unique name and stores data in specific path. When we open a file for reading or writing, it is known as stream.

What is Stream?

Stream is a sequence of bytes. There are two types of streams are used:

  1. Input stream
    This stream is used to read data from file, which is known as read operation.
  2. Output stream
    This stream is used to write data into file, which is known as write operation.

Namespace to use for file operations

In C#, System.IO namespace is used to perform file operations.

There are following file operations used in C#:

  1. Creation of file
  2. Deletion of file
  3. Reading data from file
  4. Writing data into file
  5. Appending data into file
  6. Opening a file
  7. Closing a file etc...

There are following classes are used file handling in C#:

  1. BinaryReader
  2. BinaryWriter
  3. BufferedStream
  4. Directory
  5. DirectoryInfo
  6. DriveInfo
  7. File
  8. FileInfo
  9. FileStream
  10. MemoryStream
  11. Path
  12. StreamReader
  13. StreamWriter
  14. StringReader
  15. StringWriter

There are following file modes used in C#:

  1. Open
  2. Create
  3. CreateNew
  4. OpenOrCreate
  5. Append
  6. Truncate





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL








Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.