怎么把文件里面的东西输入到我的Text里面去??
解决方案 »
- 谁帮忙解释下每行代码 具体点
- 初学者,请教参数传递
- C#怎样使TextBox里内容更新时它的垂直下拉条自动处于最下方(效果要好)
- cmd.Parameters.ADD(...) 与 new SqlParameter (....)的区别
- tabControl页面重用
- 请对datagrid和tree熟悉的前辈指教(如何将datagrid,tree整和到一起)
- ==问个很简单,但很不确定的问题==
- C#在textbox1输入ID回车键显示数据库的内容分别显示在textbox2,textbox3,textbox4
- 请问怎样远程登陆数据库,并操作数据库?
- 怎样在MDI窗体菜单中调用当前活动子窗体的事件?如:调用子窗体中的保存按钮的click事件
- 问一个VS.NET工具关于异常处理的设置在哪里
- 初级问题:我新建了一个C# WINDOWSAPPLICATION ,新建了一个类,写了一个方法
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
this.richTextBox1.Text.Append(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
MessageBox.Show("The file could not be read:" + e.Message);
}
try
{ // 创建一个StreamReader的实例,用它来读取一个文件。
// using语句会自动关闭这个StreamReader(具体为什么就去看看MSDN吧,说得很清楚的,IDisposable).
using (StreamReader sr = new StreamReader("TestFile.txt"))
{
String line;
// 一行一行的读取文件并显示(到richtextbox中)出来,直到文件被读取完毕.
while ((line = sr.ReadLine()) != null)
{
this.richTextBox1.Text.Append(line);
}
}
}
catch (Exception e)
{
// 让用户知道发生了什么错误.
MessageBox.Show("The file could not be read:" + e.Message);
}
this.richTextBox1.Text.Append(line);改成this.richTextBox1.AppendText(line);
{
string s = "";
try
{
StreamReader sr = new StreamReader(fn, Encoding.GetEncoding("GB18030"));
s = sr.ReadToEnd();
sr.Close();
}
catch { }
return s;
}