Stream is basically used for sequence of bytes passing through communication path or targeted file path.
Stream provides a generic view of a sequence of bytes. It is an abstract class.
To use stream you need to include or import System.IO namespace to the project.
Syntax:
FileStream fw = File.Open("test.txt", FileMode.Open);
There are two types of stream.
Input stream:
Input stream is used to reading data to a file.
It is used for read operation.
Output stream:
Output stream is used to write data to a file.
It is used for write operation.
Example:
using System; using System.IO; using System.Text; class Program { static void Main() { try { FileStream fw = File.Open("test.txt", FileMode.Open); //Get the length of this stream. Console.WriteLine(fw.Length); //get or set current position of this stream. Console.WriteLine(fw.Position); //Get a boolean value to check current stream supports reading. Console.WriteLine(fw.CanRead); } catch(Exception ex) { Console.WriteLine(ex.Message.ToString()); } } }
Output:
40
0
Trues
40
0
Trues
Input and output class
To use input and output class include or import System.IO and System.IO.Text namespace to the project.
It is used to perform numerous with files such as creating, removing, closing, reading and writing, to a file.
you can also visit: www.mybook-lang.com
No comments:
Post a Comment