yunyi:可以用文件长度和读到地字节作比较阿
(发表于2002-9-15 20:46:00)
busy:CFile实际上是使用windows file api(如createfile,readfile等)
先看看windows file api是怎么处理的吧。
1。同步读取文件
// Attempt a synchronous read operation.
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead, NULL) ;
// Check for end of file.
if (bResult && nBytesRead == 0, )
{
// we're at the end of the file
}
(发表于2002-11-13 15:18:00)
busy:
2。异步读取文件
// set up overlapped structure fields
gOverLapped.Offset = 0;
gOverLapped.OffsetHigh = 0;
gOverLapped.hEvent = hEvent;
// attempt an asynchronous read operation
bResult = ReadFile(hFile, &inBuffer, nBytesToRead, &nBytesRead,
&gOverlapped) ;
// if there was a problem, or the async. operation's still pending ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
// during the call to ReadFile
// code to handle that
}
(发表于2002-11-13 15:19:00)
busy:case ERROR_IO_PENDING:
{
// asynchronous i/o is still in progress
// do something else for a while
GoDoSomethingElse() ;
// check on the results of the asynchronous read
bResult = GetOverlappedResult(hFile, &gOverlapped,
&nBytesRead, FALSE) ;
// if there was a problem ...
if (!bResult)
{
// deal with the error code
switch (dwError = GetLastError())
{
(发表于2002-11-13 15:22:00)
busy:
case ERROR_HANDLE_EOF:
{
// we're reached the end of the file
//during asynchronous operation
}
// deal with other error cases
}
}
} // end case
// deal with other error cases
} // end switch
} // end if
(发表于2002-11-13 15:22:00)
busy:一般是同步读取的了。所以只要判断readfile返回的值是 true与读出来的字节为0就好了。
(发表于2002-11-13 15:25:00)
..........................................................................
--------------------next---------------------