2014-12-06 61 views
1

我有一個文件(d:/d.txt)我正在轉換爲字節數組,然後用encrytping 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; 

的數組,但現在我想轉換陣列迴文件中我怎麼能做到這一點

+0

只需打開一個文件並將其寫入文件即可。 – cup 2014-12-06 14:01:54

+0

你應該在'using'塊中確實擁有'fs',你並沒有關閉你打開的FileStream來讀取文件。也可以用'return File.ReadAllBytes(「D:/d.txt」)替換所有代碼;' – 2014-12-06 17:25:16

回答

1

試試這個:

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()); 

文檔

System.IO.File.WriteAllBytes - MSDN

相關問題