好吧,所以我正在編寫另一個程序來處理二進制文件。該程序導入的文件比我之前操作的任何文件都大,大約爲12K。FileStream讀/寫
我很好奇Stream.read命令如何工作....我知道這聽起來很基本,但我怎麼能告訴文件已被完全讀取,以便我可以開始操作它,截至現在我有這樣的代碼......
// Opens a stream to the path chosen in the open file dialog
using (FileStream stream = new FileStream(chosenFile, FileMode.Open, FileAccess.Read))
{
size = (int)stream.Length; // Returns the length of the file
data = new byte[size]; // Initializes and array in which to store the file
stream.Read(data, 0, size); // Begins to read from the constructed stream
progressBar1.Maximum = size;
while (byteCounter < size)
{
int i = data[byteCounter];
byteCounter++;
progressBar1.Increment(1);
}
}
我明白,這是非常非常簡單,但能有人向我解釋stream.Read是如何工作的,它都存儲到字節數組「數據」,然後我可以在我看來合適的情況下操作它,或者在讀取文件時必須操作文件。我再次道歉,如果這是基本的,所有的心思都讚賞
http://msdn.microsoft.com/en-us/library/system.io.filestream.read.aspx – 2012-08-08 20:56:06