. Net encapsulates streaming. Therefore, when we use C # For stream operations, we can directly use the encapsulated advanced streamreader and streamwritter to read and write texts, you do not need to use binary to read or write text. This is convenient and convenient, but it is always feasible to use binary to perform text operations. After all, the essence of a text stream is a binary stream.
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. IO; // The domain name space required for stream operations
Namespace stream
{
Class Program
{
Static void main (string [] ARGs)
{
String Path = @ "E: streamtext.txt ";
Streammanipulation. Write (PATH );
Streammanipulation. Read (PATH );
}
}
Class streammanipulation
{
Public static void write (string path)
{
Streamwriter Sw = new streamwriter (path, false );
Sw. writeline ("welcome to the stream world! ");
Sw. writeline ("Come on! ");
Sw. Close ();
}
Public static void read (string path)
{
Streamreader sr = new streamreader (PATH );
String S;
While (! Sr. endofstream)
{
S = Sr. Readline ();
Console. writeline (s );
}
Console. Read ();
}
}
}