111,095
社区成员




/// <summary>
/// 读取文本文件
/// </summary>
/// <param name="Ppath"></param>
/// <param name="Pmess"></param>
/// <returns></returns>
public static List<string> ReadTxtFile(string Ppath, out string Pmess)
{
//抛出信息
Pmess = "";
List<string> Alist = new List<string>();//读取前准备
//连接
try
{
FileStream Afs = new FileStream(Ppath, FileMode.Open);
StreamReader Asr = new StreamReader(Afs, Encoding.GetEncoding("gb2312"));
try
{
string AstrLine = "";
//开始读取
while (AstrLine != null)
{
AstrLine = Asr.ReadLine();
if (AstrLine != null && AstrLine.Trim().Length > 0)
{
Alist.Add(AstrLine);
}
}
//关闭读取流
Asr.Close();
Afs.Close();
return Alist;
}
catch (Exception ex)
{
Pmess = ex.Message;
return Alist;
}
}
catch (Exception exOut)
{
Pmess = exOut.Message;
return Alist;
}
}
if (File.Exists(@"../../test.txt"))//路径和文件类型自己设置
{
StreamReader sr = new StreamReader(@"../../test.txt", true);
string str = sr.ReadLine();
if (str != null)
{
txtZhangHao.Text = str.Trim();
}
sr.Close();
}