初学关于readline 的问题 我想从一个文本文件中读取所有的数据,但是使用 readline 只能读取一个回车符以前的字符,请教各位介绍合适的方法。谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://msdn.microsoft.com/zh-cn/library/system.io.file.readalllinesFile.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(); //点击打开按钮的事件 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); } } VS里工具箱每次都会加载项目里的文件,导致很慢,如何解决? c#垃圾回收导致蓝屏死机 ActiveX控件用不了 各位高手, 进来帮帮忙啊!~ 各位帮忙解决个foreach的小问题啊 变量取值问题 简单的程序。高手帮忙 初学c#,希望各位老大推荐一些好书! 当我把记事本的内容引入一个textbox控件时,所有的中文都变成乱码了,不知道该怎么处理? 查询后,dataGrid中如何实现鼠标单击某个单元格时该单元格便出现一个comboBox控件??? 求救:C#里AnimateWindow函数实现窗体特效,this.Close()关闭该窗体发生异常 GridView数据绑定时不显示
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();
//点击打开按钮的事件
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);
}
}