private void button1_Click(object sender, System.EventArgs e)
{
FileStream fs;
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
textBox2.Text = openFileDialog1.FileName;
try
{
fs = File.OpenRead(textBox2.Text);
byte[] arr = new byte[fs.Length];
UTF8Encoding data =new UTF8Encoding(true);
while(fs.Read(arr,0,arr.Length)>0)
{
textBox1.Text = data.GetString(arr);
}
}
catch
{
MessageBox.Show("读取文件时出错","错误",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Warning);
return;
}
}
}
[此贴子已经被作者于2006-9-7 14:29:48编辑过]