一个简单的读取文件内容的接口,将文件内容读取到字符串返回。
class ShowError
{
public static void MsgBox(string text)
{
LogFile.Log(text);
// MessageBox.Show(text);
}
}
//读取文件中内容并返回字符串
private string FileContentReader(string filePathName)
{
string fileContent = "";
try
{
// 创建一个 StreamReader 的实例来读取文件
// using 语句也能关闭 StreamReader
using (StreamReader sr = new StreamReader(filePathName))
{
string line;
// 从文件读取并显示行,直到文件的末尾
while ((line = sr.ReadLine()) != null)
{
line += "\n";
fileContent += line;
}
}
}
catch (Exception e)
{
ShowError.MsgBox("邮件内容读取错误");
}
return fileContent;
}