System.IO.IOException问题,请教高手
要实现的功能:点击一个按钮的click事件,弹出一个“打开文件对话框”,选择好文件之后,显示再显示一个保存文件对话框。每次运行到下列程序的最后那行就会出错,出错信息如下:
未处理的“System.IO.IOException”类型的异常出现在 mscorlib.dll 中。
其他信息: The process cannot access the file 'F:\Backup\My Documents\5252.hex' because it is being used by another process.
望高手指点!非常感谢!
FileStream ^fStream;
StreamReader ^sReader;
Stream ^myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
//Set the parameters for the open file dialog box
openFileDialog1->Filter = "TXT files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 1;
openFileDialog1->RestoreDirectory = true;
//Open the dialog
openFileDialog1->ShowDialog();
//if they pressed OK and a file was selected
myStream = openFileDialog1->OpenFile();
//Try to open the file to read
fStream = gcnew FileStream(openFileDialog1->FileName, FileMode::Create, FileAccess::Write,FileShare::None);
sReader = gcnew StreamReader(fStream);
FileStream ^fStream2;
StreamWriter^ sWriter;
Stream^ myStream2;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "Hex files (*.hex)|*.hex|All files (*.*)|*.*";
saveFileDialog1->FilterIndex = 1;
saveFileDialog1->AddExtension = "hex";
saveFileDialog1->ShowDialog() ;
myStream2 = saveFileDialog1->OpenFile();
//Try to open the file to write
fStream2 = gcnew FileStream(saveFileDialog1->FileName,FileMode::Create, FileAccess::ReadWrite,FileShare::ReadWrite);