[英]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 我有一个文件(D:/d.txt),正在将其转换为字节数组,然后使用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
- MSDNSystem.IO.File.WriteAllBytes
-MSDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.