1.概要
string[] readLines = File.ReadAllLines(f2);
foreach (string str in readLines) {
Console.WriteLine(str);
}
2.代码
using System;
using System.Collections.Generic;
using System.IO;
namespace ConsoleApp11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string fileName = "test.txt";
string f2 = Path.Combine(GetFolderPath(), fileName);
ReadAllLines(f2);
Console.ReadKey();
}
static string GetFolderPath() {
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
static void ReadAllLines(string f2) {
string[] readLines = File.ReadAllLines(f2);
foreach (string str in readLines) {
Console.WriteLine(str);
}
}
}
}
3.运行结果