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

📄 c8-03.cs

📁 一本很好的教材.C#开发者必备.内容全面,很难得哦.
💻 CS
字号:
//引发异常示例
using System;
using System.IO;
public class ProcessFile
{
   public static void Main()
      {
         try
            //打开一个文本文件
         {
            FileStream fs = new FileStream("data.txt", FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            string line;
            //从文件中读出数据并输出到控制台
            line = sr.ReadLine();
            Console.WriteLine(line);
         }
         catch(FileNotFoundException e)
         {
            Console.WriteLine("[数据文件丢失] {0}", e);
            throw new FileNotFoundException("[没有找到data.txt文件]");
         }
      }
}

⌨️ 快捷键说明

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