zoukankan      html  css  js  c++  java
  • 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] = {''};

    BYTE buf[4096] = {''};
    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,'',sizeof(BYTE)); memset(RecvBuf,'',4096);
    }
           
  • 相关阅读:
    【Java例题】8.1手工编写加法器的可视化程序
    【Java例题】7.6文件题3-文本文件统计
    【Java例题】7.4 文件题1-学生成绩排序
    【Java例题】7.5 文件题2-学生成绩统计
    【Java例题】7.3 线程题3-素数线程
    Map
    sql常用函数
    面向对象的理解
    attr
    webService之wsdl文档
  • 原文地址:https://www.cnblogs.com/ouzai/p/10496705.html
Copyright © 2011-2022 走看看