2012-09-06 219 views

回答

0

寫完後沖洗,然後再讀取。

順便說一下,爲什麼不顯示它從內存中?

4
var fs = new System.IO.FileStream(fileName, System.IO.FileAccess.ReadWrite); 

,然後你可以調用

long oldPos = fs.Position; 
fs.Write(....); 
fs.Flush(); 
fs.Position = oldPos; 
fs.Read(...); 
1

您可以打開FileStream用於讀取和寫入。例如:

byte[] writeBuffer; // Contains data to write 
byte[] readBuffer; // Large enough space to read data 
FileStream fileStream = new FileStream("file.txt", 
    FileMode.OpenOrCreate, FileAccess.ReadAndWrite); 
fileStream.Write(writeBuffer, 0, writeBuffer.Length); 
fileStream.Seek(0, SeekOrigin.Begin); 
fileStream.Read(readBuffer, 0, readBuffer.Length); 

您可以使用相同的對象做讀取和寫入。但是,同時執行這兩個操作需要在應用程序中仔細協調,以防止操作相互干擾。更好的解決方案可能是排列操作。