.

C Sharp File I/O Assignment Help

FILE I/O

  • A file is a set of huge source of information in a hard disk
  • It has an associated name and address
  • Reading and Writing operation in a file is called stream
  • The sequence of bytes moving in motion is a stream
  • There are 2 main streams existing in c#. They are
  • Input Stream and Output Stream.
  • Reading data from file is an Input Stream (read) and
  • Writing data to the file is an output stream (write).

C Sharp File I/O Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com


Input /Output Classes

The System.IO Namespace includes number of classes for operating files. The classes are

BinaryReader

Binary Writer

Directory

DriveInfo

DirectoryInfo

BufferedStream

FileInfo

File

MemoryStream

FileStream

StreamReader

StringReader

StreamWriter

StringWriter

Path

The FileStream className

The namespace System.IO has the classNameFileStream which is used for reading and writing operations in a file

To open a new or an existing file , an object for the classNameFileStream to be created

Syntax

FileStream object = new FileStream (filename, filemode, fileaccess, fileshare);

Example

FileStream F = new FileStream("sample.txt", FileMode.Open, FileAccess.Read,FileShare.Read);

where

filename can be any valid file name in the disk

FileMode can be Create, Append, , CreateNew, Open, Truncate and OpenOrCreate,

FileAccess can be Read, Write and ReadWrite

FileShare can be Read, Write, ReadWrite, Inheritable, None,

Example

file io image 1

Advanced File Operations in C#

The advanced file operations can be achieved through the classes listed below

StreamReader, StreamWriter , BinaryReader and BinaryWriter

The first two helps in reading and writing into text files

The rear two help in reading and writing into binary files

.