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

📄 ioexample.cs

📁 学生注册管理系统
💻 CS
字号:
using System;
using System.IO;

public class IOExample
{
  static void Main() {   
    FileStream fs;
    StreamReader srIn;
    StreamWriter sw;

    // Read operations should be placed in a try-catch block.
    try {
      // Create a FileStream and a StreamReader
      fs = new FileStream("data.dat", FileMode.Open );
      srIn = new StreamReader(fs);

      // Read the first line from the file. 
      string line = srIn.ReadLine();

      Console.WriteLine("line = "+line);
      srIn.Close();

      // Open a StreamWriter based on the same FileStream. 
//      fs = new FileStream("data.dat", FileMode.Open );
//      sw = new StreamWriter(fs);

      // write a line to the file
//      string newLine = "Not so different from you and me";
//      sw.WriteLine(newLine);

      // close the streams
//      fs.Close();
//      srIn.Close();
//      sw.Close();
    }
//    catch (FileNotFoundException fnfe) {
//Console.WriteLine("FileNotFoundException occurred: "+fnfe);
      // Perform exception handling details omitted.
//    }
    catch (IOException ioe) {
Console.WriteLine("IOException occurred: "+ioe.Message);
      // Perform exception handling details omitted.
    }
  }
}

⌨️ 快捷键说明

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