📄 filereaddemo.cs
字号:
using System;
using System.IO;
using System.Text;
class FileReadDemo
{
public static void Main()
{
string path;
Console.WriteLine ("请输入要读取的文件名。 指定带路径的完整名称:");
path = Console.ReadLine ();
try
{
if (!File.Exists(path))
{
Console.WriteLine("文件不存在");
}
else
{
// 打开流以进行读取。
FileStream fs = File.OpenRead(path);
//创建一个 byte 数组以读取数据
byte[] arr = new byte[100];
UTF8Encoding data = new UTF8Encoding(true);
//继续读完文件中的所有数据
while (fs.Read(arr,0,arr.Length) > 0)
{
Console.WriteLine(data.GetString(arr));
}
}
}
catch(Exception ex)
{
Console.WriteLine("出现错误: " + ex.Message);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -