从一个byte []文件保存在C#.NET 3.5存在、文件、byte、NET

由网友(爱不解释)分享简介:我的TCP客户端收到packet.The图像内的图像融为一体pressed与zlib.The任务是DECOM preSS的图像,并把它的形式。My TCP Client receives a image within a packet.The image is compressed with zlib.The tas...

我的TCP客户端收到packet.The图像内的图像融为一体pressed与zlib.The任务是DECOM preSS的图像,并把它的形式。

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.

我正打算救COM pressed图像在当前目录下,DECOM preSS并加载DECOM pressed文件的形式。

I'm planning to save the compressed image in the current directory,decompress it and load the decompressed file on the form.

第一个问题带有保存文件(COM pressed).The zlib的可以将它保存DECOM pressed。

The first problem comes with saving the file(compressed).The zlib can save it decompressed.

在code以下加载COM pressed文件后DECOM pression保存它。

The code below loads the compressed file and saves it after decompression.

    private void decompressFile(string inFile, string outFile)
	{
		System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
		zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outFileStream);
		System.IO.FileStream inFileStream = new System.IO.FileStream(inFile, System.IO.FileMode.Open);			
		try
		{
			CopyStream(inFileStream, outZStream);
		}
		finally
		{
			outZStream.Close();
			outFileStream.Close();
			inFileStream.Close();
		}
	}

    public static void CopyStream(System.IO.Stream input, System.IO.Stream output)
	{
		byte[] buffer = new byte[2000];
		int len;
		while ((len = input.Read(buffer, 0, 2000)) > 0)
		{
			output.Write(buffer, 0, len);
		}
		output.Flush();
	}

如何直接通过byte []数组该功能? 我打算将其保存为COM pressed,然后调用与COM pressed文件的位置的功能,但我不知道怎么都不保存文件从一个byte []数组,也不是的方式来传递的byte []数组作为输入文件。

How to pass the byte[] array directly to that function? I'm planning to save it as compressed and then call the function with the location of the compressed file,but I don't know neither how to save a file from a byte[] array nor a way to pass the byte[] array as the input file.

任何帮助将是非常美联社preciated。

Any help will be highly appreciated.

感谢。

推荐答案

使用的静态无效System.IO.File.WriteAllBytes(字符串路径,byte []的字节)方法。

Use the static void System.IO.File.WriteAllBytes(string path, byte[] bytes) method.

byte[] buffer = new byte[200];
File.WriteAllBytes(@"c:data.dmp", buffer);
阅读全文

相关推荐

最新文章