Click here to Skip to main content
15,906,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 19-May-12 3:23am
v2
Comments
Umer Aziz Malik 19-May-12 11:37am    
In my opinion the 2 solutions below from OriginalGriff & Clifford Nelson are both perfect depending upon what your exact requirement is :)

Good luck with the compression algorithm - I suspect that it will be a lot less successful than you think...:laugh:

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

To write it again:
C#
File.WriteAllBytes(path, bytes);
 
Share this answer
 
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900