好吧,所以我正在编写另一个程序来处理二进制文件。该程序导入的文件比我之前操作的任何文件都大,大约为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