V
VGA
Unregistered / Unconfirmed
GUEST, unregistred user!
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream, youStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c://" ;
openFileDialog1.Title = "打开源文件";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
myStream = File.OpenRead(openFileDialog1.FileName);
}
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = "c://";
saveFileDialog1.Title = "另存文件为";
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
youStream = File.OpenWrite(saveFileDialog1.FileName);
}
byte [] buf = new byte[512];
int intRead = 0;
intRead = myStream.Read(buf, 0, buf.Length);
// 此句出错
youStream.Write(buf, 0, intRead);
// 此句出错
myStream.Close();
youStream.Close();
}
应该怎样写? (初学C#, 见笑)
{
Stream myStream, youStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c://" ;
openFileDialog1.Title = "打开源文件";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
myStream = File.OpenRead(openFileDialog1.FileName);
}
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = "c://";
saveFileDialog1.Title = "另存文件为";
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
youStream = File.OpenWrite(saveFileDialog1.FileName);
}
byte [] buf = new byte[512];
int intRead = 0;
intRead = myStream.Read(buf, 0, buf.Length);
// 此句出错
youStream.Write(buf, 0, intRead);
// 此句出错
myStream.Close();
youStream.Close();
}
应该怎样写? (初学C#, 见笑)