简体   繁体   中英

Convert byte array to file

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM