怎麼清空一個用CreateFile打開的文件呢,文件是GENERIC_READ|GENERIC_WRITE的,
用FlushFileBuffers嗎?怎麼無法清空呢?
謝謝!
http://community.csdn.net/Expert/topic/3965/3965695.xml?temp=.7716333

解决方案 »

  1.   

    SetLength(0) ; 这样就啥都没有了。
      

  2.   

    FlushFileBuffers 是把缓冲区的内容写进文件中。 The FlushFileBuffers function flushes the buffers of the specified file and causes all buffered data to be written to the file. 
      

  3.   

    是不是繁体字看不到阿
    我转换一下把
    问题是:
    怎么清空一个用CreateFile打开的文件呢,文件是GENERIC_READ|GENERIC_WRITE的,
    用FlushFileBuffers吗?怎么无法清空呢?
    谢谢!
    http://community.csdn.net/Expert/topic/3965/3965695.xml?temp=.7716333
      

  4.   

    To  sungengyu(快乐机器) 
    具體怎麼做呢?假設hFile是CreateFile的return,
    好像沒有SetLength Function!!
     
      

  5.   

    如果用的CFile的话,SetLength(0) ; 就可以。如果用的SDK,可以参考 CFile::SetLength 的实现,大概是先 SetFilePointer,然后在 SetEndOfFile
      

  6.   

    developCpp(DevC++) :你用 CFile::SetLength() ,调试一下,就能看到 CFile::SetLength()的实现,在……\Microsoft Visual Studio\VC98\MFC\SRC\FILECORE.CPP 中。如果不好找我给你贴一下:
    void CFile::SetLength(DWORD dwNewLen)
    {
    ASSERT_VALID(this);
    ASSERT(m_hFile != (UINT)hFileNull); Seek((LONG)dwNewLen, (UINT)begin); if (!::SetEndOfFile((HANDLE)m_hFile))
    CFileException::ThrowOsError((LONG)::GetLastError());
    }CFile::SetLength 又调用了 CFile::Seek LONG CFile::Seek(LONG lOff, UINT nFrom)
    {
    ASSERT_VALID(this);
    ASSERT(m_hFile != (UINT)hFileNull);
    ASSERT(nFrom == begin || nFrom == end || nFrom == current);
    ASSERT(begin == FILE_BEGIN && end == FILE_END && current == FILE_CURRENT); DWORD dwNew = ::SetFilePointer((HANDLE)m_hFile, lOff, NULL, (DWORD)nFrom);
    if (dwNew  == (DWORD)-1)
    CFileException::ThrowOsError((LONG)::GetLastError()); return dwNew;
    }
      

  7.   

    SetFilePointer
    SetEndOfFilehaha
    thank you!