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

📄 ex-21-06

📁 Programming Csharp Source Code(代码) Programming Csharp Source Code
💻
字号:
// Example 21-06: Reading and writing to a text file

namespace Programming_CSharp
{
   using System;
   using System.IO;

   class Tester
   {
      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()
      {
         // open a file
         FileInfo theSourceFile = new FileInfo(
            @"C:\test\source\test.cs");

         // create a text reader for that file
         StreamReader reader = theSourceFile.OpenText();

         // create a text writer to the new file
         StreamWriter writer = new StreamWriter(
            @"C:\test\source\test.bak",false);

         // create a text variable to hold each line
         string text;

         // walk the file and read every line
         // writing both to the console
         // and to the file
         do
         {
            text = reader.ReadLine();
            writer.WriteLine(text);
            Console.WriteLine(text);
         } while (text != null); 

         // tidy up
         reader.Close();
         writer.Close();
      }
   }
}

⌨️ 快捷键说明

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