C# 文件读写Helper类

时间:2021-12-16 16:25:04
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; namespace PrintLableCode
{
class FileHelper
{
List<string> readList = null;
/// <summary>
/// 读取文件
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public List<string> readFiles(string path)
{
StreamReader reader = new StreamReader(path,Encoding.Default);
string lines;
while((lines=reader.ReadLine())!=null)
{
readList.Add(lines.ToString());
}
return readList;
}
/// <summary>
/// 文件写入
/// </summary>
/// <param name="path"></param>
/// <param name="str"></param>
public void writeFiles(string path,string str)
{
FileStream fs = new FileStream(path, FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(str);
sw.Flush();
sw.Close();
}
}
}