如何读取文本文件的内容(我写的函数有乱码)?
StringBuilder GetFileContent(string thePath)
{
StringBuilder sb = new StringBuilder();
try
{
using (TextReader sr = new StreamReader(thePath))
{
String line;
while ((line = sr.ReadLine()) != null)
{
sb.Append(line);
sb.Append("\n");
}
}
}
catch (Exception e)
{
sb.Append("读取文件错误"+e.ToString());
}
return sb;
}
这是我写的一个读取文本文件内容的函数,thePath为文本文件的路径
但是返回的字符串值会有乱码,不知如何解决。
请高手指点。在线等
解决马上结贴