io流
请高手指教 怎么写io流 主要功能读写txt文件 谢谢 --------------------编程问答--------------------protected void Page_Load(object sender, EventArgs e)--------------------编程问答-------------------- using System.Text;
{
if (!this.IsPostBack)
{
string Path = Server.MapPath("2.txt");//路径
insertStr(Path);
}
}
//读取文件
public void insertStr(string Path)
{
string strLine = "";
int i = 0;
try
{
StreamReader sr = new StreamReader(Path, Encoding.GetEncoding("GB2312"));
strLine = sr.ReadLine();
while (strLine != null)
{
Response.Write(strLine + "<br>");
strLine = sr.ReadLine();
i++;
}
Response.Write(i);
sr.Dispose();
sr.Close();
}
catch
{
}
}
using System.IO;
--------------------编程问答-------------------- public void wirte(string path)
{
string context = "";
Stream s =null;
StreamWriter sw =null;
try
{
s = File.Open(path, FileMode.OpenOrCreate);
sw = new StreamWriter(s, Encoding.GetEncoding("GB2312"));
sw.Write(context);
}
catch(Exception)
{
}
finally
{
s.Dispose();
s.Close();
sw.Dispose();
sw.Close();
}
} --------------------编程问答-------------------- baidu一下就有答案。
主要的类就是那个几个: Stream相关的 --------------------编程问答-------------------- 0.0.求正解 --------------------编程问答-------------------- MSDN中就有详细的示例:http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx
补充:.NET技术 , ASP.NET