读文件[C#] 纯文本查看 复制代码 protected string Read_Txt(string filename)
{
Encoding code = Encoding.GetEncoding("gb2312");
string temp = HttpContext.Current.Server.MapPath("Precious\\" + filename + ".txt");
string str = "";
if (File.Exists(temp))
{
StreamReader sr = null;
try
{
sr = new StreamReader(temp, code);
str = sr.ReadToEnd(); // 读取文件
}
catch { }
sr.Close();
sr.Dispose();
}
else
{
str = "";
}
return str;
}
转成字节
[C#] 纯文本查看 复制代码 Byte[] MyData = System.Text.Encoding.UTF8.GetBytes(“你的字符串”);
|