从一个byte []文件保存在C#.NET 3.5 [英] Save file from a byte[] in C# NET 3.5

查看:140
本文介绍了从一个byte []文件保存在C#.NET 3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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);

这篇关于从一个byte []文件保存在C#.NET 3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆