读书人

初学关于readline 的有关问题

发布时间: 2012-12-15 15:16:03 作者: rapoo

初学关于readline 的问题
我想从一个文本文件中读取所有的数据,但是使用 readline 只能读取一个回车符以前的字符,请教各位介绍合适的方法。谢谢。
[最优解释]


//点击打开按钮的事件
private void miOpen_Click(object sender, EventArgs e)
{
OpenFileDialog dig=new OpenFileDialog();
dig.ShowDialog();
if (dig.FileName!="")
{
SetTitle(dig.FileName);
filename = dig.FileName;
OpenFile(dig.FileName);//调用OpenFile方法
}
else
{
MessageBox.Show("请选择文件!");
}

}

//打开文件的方法
protected void OpenFile(string path)
{
try
{
textBox1.Clear();
textBox1.Text = File.ReadAllText(path, UnicodeEncoding.GetEncoding("GB2312")); //文件的读取
}
catch(IOException e)
{
MessageBox.Show(e.Message, "hhh",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}

[其他解释]
http://msdn.microsoft.com/zh-cn/library/system.io.file.readalllines

File.ReadAllLines 方法
[其他解释]

string path = @"E:\CollegeStudy\c# 资料\C__WCF入门学习.txt";
StreamReader sr = new StreamReader(path, Encoding.GetEncoding("GB2312"));
string text = sr.ReadToEnd();
Console.WriteLine(text);
sr.Close();

------其他解决方案--------------------


如果不在控制台里输出,在一个文本框里输出所有数据呢?
[其他解释]

引用:
C# code??12345678910111213141516171819202122232425262728293031//点击打开按钮的事件 private void miOpen_Click(object sender, EventArgs e) { OpenFileDialog dig=new OpenFileD……

很有用,谢谢。

读书人网 >C#

热点推荐