c#如何从任何文件读取二进制文件,然后将二进制文件重写为新文件 [英] c# How do I read binary from any file, then rewrite the binary to a new file

查看:99
本文介绍了c#如何从任何文件读取二进制文件,然后将二进制文件重写为新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何从任何文件读取二进制文件,然后将二进制文件重写为新文件.

这是必需的,因为我试图压缩二进制文件,然后将其重写为一个新文件,以解压缩该文件,同时保持所有内容不变.

这适用于C#Express 2010项目.

我想出了一种方法来获得1MB到100k的费用.如何做到这一点是通过搜索重复的代码(100000010)等,然后创建一个存储代码位置的数组,而不是代码本身.

Hi
How do I read binary from any file, then rewrite the binary to a new file.

This is needed, because I am trying to compress the binary, then rewrite it to a new file, with the aim to uncompress it, keeping all contents intact.

This is for a C# Express 2010 Project.

I figured out a way to get 1MB, to mabey 100k. How this could be done is through searching for duplicate code (100000010) etc, then creating an array storing the loction of the code, rather than the code itself.

推荐答案

压缩算法祝您好运-我怀疑它会比您认为的成功要差很多...:笑:

但是,要读取二进制文件:
Good luck with the compression algorithm - I suspect that it will be a lot less successful than you think...:laugh:

However, to read binary:
byte[] bytes = File.ReadAllBytes(path);


要再次编写:


To write it again:

File.WriteAllBytes(path, bytes);


如果您的目的只是复制文件,则可以使用File.Copy.请参阅: http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx [ ^ ]
If your objective is just to copy a file, you can use the File.Copy. See: http://msdn.microsoft.com/en-us/library/system.io.file.copy.aspx[^]


这篇关于c#如何从任何文件读取二进制文件,然后将二进制文件重写为新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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