文件路径:E:\Test\log.txt
文件内容如下:
代码如下:
static void Main(string[] args)
{
Read();
Console.ReadLine();
}
public static void Read()
{
//指定文件路径
string fileName = “E:\\Test\\log.txt”;
try
{
//根据文件路径读取到文件
using (StreamReader sr = new StreamReader(fileName))
{
string line;
//判断读取文件中的每一行内容不为空
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception)
{
throw;
}
运行结果:
读取其他电脑共享文件夹下内容只需修改地址
string fileName =
@“\\192.168.250.11\\E\\log.txt”;