1. CFile file; //定义文件变量   
  2.    
  3. CString filename=L"D://test.txt";   
  4.    
  5. //modeCreate,指定构造函数创建一个新文件,如果该文件已经存在,那么将它的长度截断为0   
  6.    
  7. //modeWrite,打开文件,该文件仅用于写入操作    
  8.    
  9. /*shareDenyRead,打开文件,并且拒接其他进程堆该文件的读取或写入访问,如果该文件已经被其他进程以兼容模式打开, /*那么文件创建失败*/    
  10.    
  11. if(file.Open(filename,CFile::modeCreate|CFile::modeWrite|CFile::shareDenyRead))    
  12.    
  13. {    
  14.    
  15. file.SeekToBegin(); //到达文件开头    
  16.    
  17. file.Write("/xff/xfe", 2); //Unicode编码的txt文件以0xff、0xfe两个字节作为开头标记。   
  18.    
  19. file.Write(m_edit,m_edit.GetLength()*2); //写入实际数据    
  20.    
  21. file.Close(); //关闭文件    
  22.    
  23. MessageBox(L"数据发送成功",L"提示信息");    
  24.    
  25. else   
  26.    
  27.  {    
  28.    
  29. MessageBox(L"创建文件失败");   
  30.    
  31.  }    
  32.    
  33. /*  
  34.   
  35. ps:这里最重要的是“/Unicode编码的txt文件以0xff、0xfe两个字节作为开头标记”这句  
  36.   
  37. */