1

I have a file (D:/d.txt) that I'm converting to a byte array and then encrytping the array with RC4

 string filename="D:/d.txt" byte[] buff = null; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); long numBytes = new FileInfo(fileName).Length; buff = br.ReadBytes((int) numBytes); return buff; 

but now I want to convert the array back to a file how can I do that

2
  • Just open a file and write it to the file. Commented Dec 6, 2014 at 14:01
  • You should really have fs in a using block, you are not closing the FileStream you opened to read the file. Also all of your code could be replaced with return File.ReadAllBytes("D:/d.txt"); Commented Dec 6, 2014 at 17:25

1 Answer 1

1

try this:

 string filename = "D:/d.txt"; byte[] buff = null; FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); long numBytes = new FileInfo(filename).Length; buff = br.ReadBytes((int) numBytes); File.WriteAllBytes("Foo.txt", buff); // or File.WriteAllBytes("Foo.txt", buff.ToArray()); 

Documentation

System.IO.File.WriteAllBytes - MSDN

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.