CFileException m_cause == 11

首先贴上MSDN上的解释:

  • CFileException::none   No error occurred.

  • CFileException::genericException   An unspecified error occurred.

  • CFileException::fileNotFound   The file could not be located.

  • CFileException::badPath   All or part of the path is invalid.

  • CFileException::tooManyOpenFiles   The permitted number of open files was exceeded.

  • CFileException::accessDenied   The file could not be accessed.

  • CFileException::invalidFile   There was an attempt to use an invalid file handle.

  • CFileException::removeCurrentDir   The current working directory cannot be removed.

  • CFileException::directoryFull   There are no more directory entries.

  • CFileException::badSeek   There was an error trying to set the file pointer.

  • CFileException::hardIO   There was a hardware error.

  • CFileException::sharingViolation   SHARE.EXE was not loaded, or a shared region was locked.

  • CFileException::lockViolation   There was an attempt to lock a region that was already locked.

  • CFileException::diskFull   The disk is full.

  • CFileException::endOfFile   The end of file was reached.


第11个是:CFileException::hardIO   There was a hardware error.  没错 就是这个。


然后看到有个网友推测原因:

hz129(古雨)

是不是你生成文件的句柄还没释放,所以该文件被锁为只读或根本不能读写了?
我也没遇到过,只是我的猜想

果断正确,我有两个项目,一个项目调试中,输出文件; 启动另一个项目读取文件····· 就这么回事儿,退出前一个项目即可顺利读取,Close();


是不是你生成文件的句柄还没释放,所以该文件被锁为只读或根本不能读写了?
我也没遇到过,只是我的猜想
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
// 文件合并涵数 int CFileSpltDlg::MergeMe() { CWaitCursor wait; // constructing these file objects CFile destFile; // we'll use a CFileException object to get error information CFileException ex; BYTE buffer[140000]; DWORD dwRead; UINT nCount = 140000; UINT newlen = 1400000; char buff [20]; long l = 1; CString name; CString pref; CString newpath; UpdateData(TRUE); //open file for read if (!m_path.IsEmpty()) { if (!m_SourceFile.Open(m_path, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); m_edit.SetFocus(); m_edit.SetSel(0, -1); return 1; } //construct new name m_filename = m_path.Right((m_path.GetLength() - m_path.ReverseFind('\\')) - 1); //close file m_SourceFile.Close(); } //constuct a new path name newpath = m_path.Left(m_path.GetLength() - m_filename.GetLength()); if (!m_targetpath.IsEmpty()) { //some silly check, that could be chnged if (!m_filename.IsEmpty() && m_filename.Left(2) != _T("1_")) { ::AfxMessageBox(_T("待合并的源文件名不对..."), MB_ICONERROR); return 1; } else if(m_filename.IsEmpty()) { MessageBox(_T("请选择待合并的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } //constuct an original file name m_filename = m_filename.Right(m_filename.GetLength() - 2); //判断选择目录未尾是否已有"\"符 if(m_targetpath.Right(1)=='\\') m_path = m_targetpath + m_filename; else m_path = m_targetpath + _T("\\") + m_filename; //create target file if (!destFile.Open(m_path, CFile::modeWrite | CFile::shareExclusive | CFile::typeBinary | CFile::modeCreate, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); return 0; } } else if(m_path.IsEmpty()) {//souce is not there MessageBox(_T("请选择待合并的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } if (m_targetpath.IsEmpty()) {//target is not there MessageBox(_T("请选择合并后要保存到的目标文件夹."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } //do merge do { //constuct a new name by dynamicly incrementing prefix pref = _ltoa(l, buff, 10); pref += _T("_"); //open file with new name if (!m_SourceFile.Open(newpath + pref + m_filename, CFile::modeRead | CFile::shareExclusive | CFile::typeBinary, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); destFile.Close(); m_path = _T(""); m_filename = _T(""); // pProgress.SetPos(0); newpath = _T(""); // m_parts = _T(""); UpdateData(FALSE); //return OK because this f_n is aborting the loop if name is not found return 0; } else //constuct a new name name = _T(newpath + pref + m_filename); do {//write into file while it size < than 1.4 MB dwRead = m_SourceFile.Read(buffer, nCount); destFile.Write(buffer, dwRead); } //while we can read from source file while (dwRead > 0); m_SourceFile.Close(); // Set the range to be 0 to 500. pProgress.SetRange(0, 500); // Set the position for (int i = 0; i < 500; i++) pProgress.SetPos(i); m_parts = _ltoa(l, buff, 10); m_parts += _T("个文件已合并"); UpdateData(FALSE); l++; UpdateWindow(); } while (l < 500);//little bit dirty solution, but you can always improve it!... return 0; } //文件分割涵数 int CFileSpltDlg::SplitMe() { CWaitCursor wait; // constructing these file objects CFile destFile; // we'll use a CFileException object to get error information CFileException ex; DWORD dwRead; UINT newlen; char buff [20]; char b [20]; long l = 1; CString name; UINT len = 0; // CGradientProgressCtrl *pProgress = (CProgressCtrl*) GetDlgItem(IDC_PROGRESS); UpdateData(TRUE); //获取文件分割后的大小,定义相对应变量数值 newlen=GetSplitFileSize(); UINT nCount = newlen/10; BYTE buffer[140000]; //open file for read //m_path contain the file path if (!m_path.IsEmpty()) { if (!m_SourceFile.Open(m_path, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); m_edit.SetFocus(); m_edit.SetSel(0, -1); return 1; } //get file length len = m_SourceFile.GetLength(); } //too lazy to put all "hard coded" strings in string table else { MessageBox(_T("请选择待分割的源文件."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } if (m_targetpath.IsEmpty()) { MessageBox(_T("请选择分割后保存到的目标文件夹."), _T("文件分割器"), MB_ICONEXCLAMATION); return 1; } //quick and dirty check for file size if (len < newlen) { CString length = _itoa(len, b, 10); MessageBox(_T("文件长度为 " + length + " 字节,不够指定的分割大小, 没有必要再进行分割."), _T("文件分割器"), MB_ICONEXCLAMATION); m_SourceFile.Close(); m_path = _T(""); m_filename = _T(""); UpdateData(FALSE); return 1; } //do split do { //constuct a new name dynamicly changing prefix name = _ltoa(l, buff, 10); name += _T("_"); CString newpath; //判断选择目录未尾是否已有"\"符 if(m_targetpath.Right(1)=='\\') newpath = m_targetpath; else newpath = m_targetpath + _T("\\"); if (!destFile.Open(newpath + name + m_SourceFile.GetFileName(), CFile::modeWrite | CFile::shareExclusive | CFile::typeBinary | CFile::modeCreate, &ex;)) { TCHAR szError[1024]; ex.GetErrorMessage(szError, 1024); ::AfxMessageBox(szError); m_SourceFile.Close(); return 1; } do { dwRead = m_SourceFile.Read(buffer, nCount); destFile.Write(buffer, dwRead); }//while size is less than 1.4 MB while (dwRead > 0 && destFile.GetLength() < newlen); destFile.Close(); // Set the range pProgress.SetRange(0, len /newlen*10); // Set the position pProgress.SetPos(l); m_parts = _ltoa(l , buff, 10); m_parts += _T("个文件生成"); UpdateData(FALSE); l++; UpdateWindow(); } while (dwRead > 0); // close source m_SourceFile.Close(); m_path = _T(""); m_filename = _T(""); // pProgress.SetPos(0); // m_parts = _T(""); UpdateData(FALSE); return 0; }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值