C++下载数据至.map/.txt/.list文件
bool IsExistFile(LPCTSTR pszFileName) //判断文件是否存在 { WIN32_FIND_DATA FindFileData; HANDLE hFind; hFind = ::FindFirstFile(pszFileName,&FindFileData); if(hFind == INVALID_HANDLE_VALUE) return false; else { FindClose(hFind); return true; } return false; }
bool DataInteraction(int nSendLen, int nHolpRecv, int& nRecvLen, int nDevID) //写入文件
{
BYTE RecvBuf[4096] = {'\0'};
BYTE buf[4096] = {'\0'};
string strr = ""; string strr1 = ""; strr1 = str09B; if(str09B == "") 输入文件名 { return false; } strr = "C:\\MSG\\" + strr1; CFile file; BOOL IsFile = IsExistFile(strr.c_str()); if(IsFile == FALSE) { file.Open(strr.c_str(),CFile::modeCreate|CFile::modeReadWrite); 读写属性新建文件 } else { if (remove(strr.c_str()) == 0) 删除后新建,可不要 { Sleep(5); file.Open(strr.c_str(),CFile::modeCreate|CFile::modeReadWrite); } else { file.Open(strr.c_str(),CFile::modeReadWrite); } }
for(int i = 0; i > 2047 || (RecvBuf[5 + i] != 0x03);i++) { buf[i] = RecvBuf[3 + i]; } int len = file.GetLength(); if(len == 0) file.Seek(0,CFile::begin); else file.SeekToEnd(); TCHAR stt[4096] = {0}; memcpy(stt,RecvBuf,sizeof(RecvBuf)); int len1 = strlen(stt); file.Write(buf,len1); 防止写入过多空格 file.Flush(); file.Close(); memset(buf,'\0',sizeof(BYTE)); memset(RecvBuf,'\0',4096);
}