62,046
社区成员
发帖
与我相关
我的任务
分享
FileStream fs = new FileStream("路径",FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs,Encoding.GetEncoding("GB2312"));
string str = sr.ReadLine();
for(int i=0; str != null;i++)
{
str = str.Replace(".","</br>");//根据"."字符,判断是否换行
Response.Write(str);
str = sr.ReadLine();
}
sr.Close();
fs.Close();
/// <summary>
/// 读文本内容
/// </summary>
/// <param name="StrFileName">文本名</param>
/// <returns>返回文本内容</returns>
public static string RreadTxtFile(string StrFileName)
{
string StrPath = string.Empty; //定义存放目录变量
StrPath = Path.GetDirectoryName(System.Web.HttpContext.Current.Request.PhysicalPath) + @"\Log\" + StrFileName + ".txt";
//判断是否有当前文件,如果有,则删除
if (File.Exists(StrPath))
{
//直接写内容文本
using (StreamReader ObjStreamReader = File.OpenText(StrPath))
{
return ObjStreamReader.ReadToEnd();
}
}
else
return null;
}