Anda di halaman 1dari 20

Submitted To: Mr.

Ankur Sir
Submitted By: Anil Ashokbhai
Nikam
File is collection of data stored on a disk
with specific name and directory path.
It is the a stream of characters or a flow
of related data.
Streams read/write bytes to/from
Storage device
It is the concept of the File input &
output operation.
Its explains the process of reading and
writing in the files and the binary files.
Its play very important role in Data
storing and retriving from a file.

Microsoft Word
For Creating File or Editing and Deleting Data from the
Document files(.Doc)
NotePad
For Creating File or Editing and Deleting Data from the
Text files (.txt)
Photoshop
For Creating File or Editing and Deleting Data from the
Image files (.psd, .gif, .jpg, .jpeg, .png, .bmp etc..)
To store useful data taken from User by
the C# application & store it
permanently in a file in a storage device
for futher use.
It can also performs process creating,
editing or deleting file.
By this we can retrive data or insert it and
perform different operation on data and
store final output in file.
System.IO namespace use for file
handling

System.IO
(Namespace)
FileStream
StreamReader
StreamWriter BinaryReader BinaryWriter
FileMode
Append
Create
CreateNew
Open
OpenOrCreate
Truncate
FileAccess
Read
Write
ReadWrite
FileShare
Inheritable
None
Read
ReadWrite
Write
To Open an existing file or to create a new file , we
need an object of FileStream Class

Syntax
FileStream <object name> = new
FileStream(<file name> , <FileMode> ,
<FileAccess> , <FileShare>);

Code Snippet
FileStream f = new FileStream(C.txt ,
FileMode.Open , FileAccess.Read ,
FileShare.Read);

Close
Close the object of that class & Stream.
Peek
Returns the next available character
but does not consume it.
Read
Read the next character.
ReadLine
Read a line of a character.
Seek
Allows the Read/Write Postion to
moved to any position within file.
Close
Closes the current object &
Stream.
Flush
Clear all bufers for the current
writer.
Write
Write to the Stream.
WriteLine
Write data specified by the
overloaded parameters followed
by end of the line.
StreamReader StreamWriter
FileStream fs = new FileStream(MyFile.txt, FileMode.Open,
FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str = sr.ReadLine();
FileStream fs = new FileStream(MyFile.txt, FileMode.Append,
FileAccess.Write);
StreamWriter w = new StreamWriter(fs);
string str = w.ReadLine();

using System;
using System.IO;

class FileRead
{
public void ReadData()
{
FileStream fs = new
FileStream(Myfile.txt,FileMode.Open,
FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string = sr.Readline();
while(str!=null)
{
Console.WriteLine({0}, str);
str = sr.ReadLine();
}
sr.Close();
fs.Close();

}
public static void Main(String[] args)
{
FileRead fr = new FileRead();
fr.ReadData();
}
}
using System.IO;

class Program
{
public static void Main(String[] args)
{
FileStream fs = new
FileStream(MyFile.txt,
FileMode.Append, FileAccess.Write);
StreamWriter w = new StreamWriter(fs);
Console.WriteLine(Enter the String);
string sr = Console.ReadLine();
w.write(str);
w.Flush();
w.Close();
fs.Close();
}
}
Close the
current reader
& stream.
Close
Read
characters from
the Stream &
advance
current postion
of stream.
Read
Close the current binary
object & stream. close
Sets the position within the
current stream. Seek
Write a value to the current
stream Write
Clear all buffer for the
current writer and causes
any bufferes data to be
written in the device
Flush
BinaryReader Class BinaryWriter Class
FileStream fs = new
FileStream(@C:\Test.DAT, FileMode.Open, FileAcces.Read);
BinaryReader br = new BinaryReader(fs);
FileStream fs = new
FileStream(@C:\Test.DAT, FileMode.Open, FileAcces.Read);
BinaryWriter bw = new BinaryReader(fs);
Visual Studio can open binary files and you can look
at the data. It won't be readable normally, but it
gives you an idea what is happening

Anda mungkin juga menyukai