problem copy file?

W

wavemill

Hello!

I would like copy a file , but i don't want use File.Copy.(in the
future i would like encrypt the file..)

This my code:

FileStream fs = new FileStream("\\Program
Files\\SmartDeviceApplicationPpc\\myBmp1.bmp", FileMode.Open,
FileAccess.Read);
FileStream fsWrite = new FileStream("\\Program
Files\\SmartDeviceApplicationPpc\\myBmp2.bmp", FileMode.Create,
FileAccess.Write,FileShare.Read);

BinaryReader r = new BinaryReader(fs);
BinaryWriter rw = new BinaryWriter(fsWrite);

int lg = Convert.ToInt32(fs.Length);
byte[] bytes = new byte[lg];
fsWrite.Write(bytes,0,lg);
for (int i = 0; i < fs.Length; i++)
{
byte mybyte = (byte)fs.ReadByte();
fsWrite.WriteByte(mybyte);
}


My file is copy but he is not complete and i can't see mybmp!

have you got any idea?

best regards

j.berdoues
 
A

Alex Feinman [MVP]

You are forgetting to close the write stream, so the last data buffer is not
written.
fsWrite.Close(); should take care of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top