private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog()!= DialogResult.OK)
{
return;
}
using (FileStream filestream = File.OpenRead(openFileDialog1.FileName))
{
using (StreamReader sr = new StreamReader(filestream,Encoding.Default))
{
string line = null;
while ((line = sr.ReadLine()) != null)
{
textBox1.AppendText(line);
}
}
}
}
创建streamreader对象的时候在第二个参数中指定编码类型是Default的(在中文系统中Default类型即为ASCII类型的)。 |