Skip to main content

Posts

Showing posts with the label Memory Stream

Reading and Writing Files with .Net

Understanding Streams : Sequential and random access streams. All stream classes inherit from Stream class , these classes include: FileStream (System.IO), MemoryStream (System.IO), CryptoStream(System.Security), NetworkStream(System.Net), GZipStream(System.Compression). File class is an important class used to open file for reading/writing, Exist, Delete, Move and etc… Create/open Methods of File will return FileStream Object. For Sequential reading and writing some methods also return StreamReader and StreamWriter and they encapsulate FileSteam object. Few simple operations are identical to FileInfo object. MemoryStream is a specialized class provided to manage data in memory stream to gain some optimization. How to read from a File : FileStream theFile = File.Open(@“C:\boot.ini”, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(thefile); Console.Write(sr.ReadToEnd()); Sr.Close(); theFile.Close(); OR StreamReader s...