private void tsmi_Open_Click(object sender, EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
byte[] bytes = new byte[myStream.Length];
int numBytesToRead = (int)myStream.Length;
string read = myStream.Read(bytes, 0, numBytesToRead).ToString();
RichTextBox1.Text = read.ToString();
myStream.Close();
}
}
}Stream.Read读不出内容 读出了长度? 输出为 6 为什么?
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
byte[] bytes = new byte[myStream.Length];
int numBytesToRead = (int)myStream.Length;
string read = myStream.Read(bytes, 0, numBytesToRead).ToString();
RichTextBox1.Text = read.ToString();
myStream.Close();
}
}
}Stream.Read读不出内容 读出了长度? 输出为 6 为什么?
解决方案 »
- 非静态成员里可以引用静态,而静态成员里却不能引用非静态成员,为啥呀?
- WinFrom 强制让Tree控件获取焦点
- 在C#中访问Exchange的问题?
- 如何做一个可以编辑位图像素的控件
- c#如何判断wenform中textbox控件是否获得焦点
- C# 读取USB vid pid
- ADOX.Catalog创建Access数据库的问题 : laccdb文件一直存在
- 一本专讲MSIL的书名忘记了,请告诉我好吗?
- 数据库更新问题!(急救)
- dll 类库如何使用全局变量
- 如何使Control在不同的分辨率下保持原有大小?
- 非静态的字段、方法或属性“DBUtility.sqlhelper.RunProc(string, System.Data.SqlClient.SqlParameter[])”要求对象引用 D:\vs2005gg\yanlei\DAL\datasq
这是获取了读到的字符长度,你读的东西在bytes里
myStream.Read(bytes, 0, numBytesToRead);
string read = System.Test.Encoding.Default.GetString(bytes);
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
StreamReader reader = new StreamReader(myStream);
RichTextBox1.Text = reader.ReadToEnd();
myStream.Close();
reader.Close();
}
}