c#???????
请问一下,在winform中有一个openfiledialogue组件,想在button事件中激发该事件添加代码如下
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.InitialDirectory == null)
open.ShowDialog();
open.Filter = "所有文档文件(*.txt)|*.txt";
open.Multiselect = false;
if (open.ShowDialog(this) == DialogResult.Cancel)
return;
string readpath = open.FileName;
string writepath = @"修改.txt";
StreamReader read = new StreamReader(readpath);
string a = read.ReadToEnd();
StreamWriter write = new StreamWriter(writepath);
write.Write(a);
MessageBox.Show("写完!");
Application.Exit();
修改.txt的内容和原文本文件(也是txt)不相符,原文本文件中被删除了一不分内容,如果直接指定地址则不会出现上述情况,为什么?
还有个问题,使用正则式也会自己删除文件内容,为什么?