In order to save the data in a file or get it from a file, you need to use a class in the System.IO namespace. These classes include the file class that represents one of the files on the disk, and the directory class that represents the catalog (also known as a folder in Windows).
The Directory class exposes static methods for creating, moving, and browsing directories. All methods of the directory class are static. Therefore, instead of creating an instance of this class, you can call all the methods of the class.
To implement the binary read and write of the file:
usingSystem;usingSystem.IO;namespaceimplementingbinaryreadwritetofile{classTester {Const intSizebuff =1024x768; Public Static voidMain () {//Create an instance and execute itTester T =NewTester (); T.run (); } //Pass it a directory name to execute it Private voidRun () {//The files that are readStream InputStream =File.openread (@"C:\test\source\test1.cs"); //the file to write toStream OutputStream =File.openwrite (@"C:\test\source\test1.bak"); //Create a cache of saved files byte[] buffer =NewByte[sizebuff]; intBytesread; //when the Read method continuously returns bytes, they are constantly written to the output data stream while((Bytesread =inputstream.read (buffer,0, Sizebuff)) >0) {outputstream.write (buffer,0, Bytesread); } inputstream.close (); Outputstream.close (); } }
C # Learning process-Data flow