My TCP Client receives a image within a packet.The image is compressed with zlib.The task is to decompress the image and put it on the form.
I\'m planning to save the co
Use the static void System.IO.File.WriteAllBytes(string path, byte[] bytes) method.
byte[] buffer = new byte[200];
File.WriteAllBytes(@"c:\data.dmp", buffer);
In addition to what everyone else has already stated, I would also suggest you use 'using' clauses since all those objects implement IDisposable.
using(FileStream outFileStream = new ...)
using(ZOutputStream outZStream = new ...)
using(FileStream inFileStream = new ...)
{
CopyStream(inFileStream, outZStream);
}
You can try this code
private void t1()
{
FileStream f1 = new FileStream("C:\\myfile1.txt", FileMode.Open);
int length = Convert.ToInt16(f1.Length);
Byte[] b1 = new Byte[length];
f1.Read(b1, 0, length);
File.WriteAllBytes("C:\\myfile.txt",b1);
f1.Dispose();
}
Stick the byte array you received into a MemoryStream
and compress/decompress it on the fly without using temporary files.
public static void SaveFile(this Byte[] fileBytes, string fileName)
{
FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
fileStream.Write(fileBytes, 0, fileBytes.Length);
fileStream.Close();
}