class1.cs

来自「150个经典的入门学习程序源代码」· CS 代码 · 共 30 行

CS
30
字号
using System;
using System.IO;

namespace Example076_从文件读取文本
{
	/// <summary>
	/// Class1 的摘要说明。
	/// </summary>
	class Class1
	{
		private const string FILE_NAME = "MyFile.txt";
		public static void Main(String[] args) 
		{
			if (!File.Exists(FILE_NAME)) 
			{
				Console.WriteLine("{0} does not exist!", FILE_NAME);
				return;
			}
			StreamReader sr = File.OpenText(FILE_NAME);
			String input;
			while ((input=sr.ReadLine())!=null) 
			{
				Console.WriteLine(input);
			}
			Console.WriteLine ("The end of the stream has been reached.");
			sr.Close();
		}
	}
}

⌨️ 快捷键说明

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