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 为什么?
解决方案 »
- 如何突破WebClient长度限制
- 请教 源数组长度不足。请检查 srcIndex 和长度以及数组的下限。
- Visual studio 2012怎么打包应用程序?
- 急!!wpf 里的WrapPanel 布局问题
- WebChart控件如何设置坐标原点。
- C#远程复制文件~~~!
- 关于Server.MapPath,在线等结果
- wcf中关于基类与继承数据序列化的问题
- 请教c# windows 应用程序 界面制作的问题:
- Ado.Net速度测试,欢迎讨论
- 如何使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();
}
}