代码如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;\\这是必须的
namespace aspnetcs
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if (!File.Exists(MapPath("weather.txt")))
{
Console.WriteLine("{0} does not exist.", MapPath("weather.txt"));
return;
}
StreamReader sr = new StreamReader(MapPath("weather.txt"), System.Text.Encoding.Default);
软件开发网 www.mscto.com
String input = sr.ReadToEnd();
sr.Close();
input = input.Replace("\r\n", "<br>").Replace("\n", "<br>");
Response.Write(input);
Response.End();//就是这上面的代码,如果用Response.WriteFile方法,虽然能读出txt文件内容,却不能显示分段格式