Programming Csharp Source Code(代码) Programming Csharp Source Code

源代码在线查看: ex-21-04

软件大小: 205 K
上传用户: fzjw0803005
关键词: Programming Csharp Source Code
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Example 21-04: Implementing a binary read and write to a file
				
				namespace Programming_CSharp
				{
				   using System;
				   using System.IO;
				
				   class Tester
				   {
				      const int SizeBuff = 1024;
				
				      public static void Main()
				      {
				         // make an instance and run it
				         Tester t = new Tester();
				         t.Run();
				      }
				        
				      // Set it running with a directory name
				      private void Run()
				      {
				         // the file to read from
				         Stream inputStream = File.OpenRead(
				            @"C:\test\source\test1.cs");
				
				         // the file to write to
				         Stream outputStream = File.OpenWrite(
				            @"C:\test\source\test1.bak");
				
				         // create a buffer to hold the bytes 
				         byte[] buffer = new Byte[SizeBuff];
				         int bytesRead; 
				
				         // while the read method returns bytes
				         // keep writing them to the output stream
				         while ( (bytesRead = 
				            inputStream.Read(buffer,0,SizeBuff)) > 0 )
				         {
				            outputStream.Write(buffer,0,bytesRead);
				         }
				
				         // tidy up before exiting
				         inputStream.Close();
				         outputStream.Close();
				      }
				   }
				}
							

相关资源