⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch8_01.cs

📁 《c#技术内幕代码》
💻 CS
字号:
using System;
using System.IO;

class CH8_1
{
   public static void CreateTextFile( string name )
   {
        try
	{
           FileStream fs = new 
               FileStream(name, FileMode.Create, FileAccess.Write);
           StreamWriter sw = new StreamWriter(fs);
  	   sw.WriteLine("Test1");
           sw.Write("This is");
           sw.Write(" ");
           sw.Write("a test\n");
           sw.Close();
	}
	catch ( Exception e )
	{
	   Console.WriteLine("Exception in CreateTextFile: {0}", e );
	}
   }
   
   public static void CreateBinaryFile( string name )
   {
        try
	{
           FileStream fs = new 
               FileStream(name, FileMode.Create, FileAccess.Write);
           BinaryWriter bw = new BinaryWriter(fs);
	
           int x = 10;
  	   double y = 20.45;
           string s = "This is a test";
	
           bw.Write(x);
           bw.Write(y);
           bw.Write(s);
	
           bw.Close();
	}
	catch ( Exception e )
	{
	   Console.WriteLine("Exception in CreateBinaryFile: {0}", e );
	}
   }
   
   public static void Main( string[] args )
   {
      if ( args.Length < 2 )
      {
         Console.WriteLine("Usage CH8_1 text-file-name binary-file-name");
         return;
      }
	 
      CreateTextFile( args[0] );
      CreateBinaryFile( args[1] );
   }
}

   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -