wince在指定的路径下 打开,读,创建,写,删除txt文件

CString strWorkPath;
 TCHAR  tszWorkPath[MAX_PATH];
 GetModuleFileName(NULL, tszWorkPath, MAX_PATH);//获取本地执行的EXE路径
 strWorkPath.Format(_T("%s"),tszWorkPath)  ;
 AfxMessageBox(strWorkPath);
 int num = strWorkPath.ReverseFind(_T('//'));
 strWorkPath = strWorkPath.Left(num);//剪除exe部分 剩下文件夹路径
 AfxMessageBox(strWorkPath);
 strWorkPath+=_T("//ping.TXT");
 AfxMessageBox(strWorkPath);//要创建的TXT文件的路径和名称

 //-------------------
 CFile file;
 if(file.Open(strWorkPath,CFile::modeReadWrite))//如果路径下的TXT文件已经存在 就读取txt的内容,否则else创建该文件
 {
  //AfxMessageBox(_T("open success!"));
  //定义读写缓冲区
  char pbuf[100];
  UINT nBytesRead = file.Read( pbuf, 100 );
  CString ss;
  ss.Format(_T("%s"),pbuf);
  //AfxMessageBox(ss);
 }
 else
 {
  file.Open(strWorkPath,CFile::modeCreate | CFile::modeReadWrite);//创建txt文件,并写入内容
  //AfxMessageBox(_T("not exist to create"));
  CString strValue = _T("61.135.169.105a"); 
  int i = strValue.GetLength()*2;
  file.Write(strValue,i);
 }
 CFile::Remove(strWorkPath);//移除txt文件
 file.Close(); //文件用完必须关闭,否则下次无法操作

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值