bin文档读写
来源:互联网 发布:linux查看程序进程号 编辑:程序博客网 时间:2024/06/10 23:50
今天遇到问题。之前测试模组的时候,保存的测试数据bin文档多了2个byte数据。
解决紧急问题当然使用最熟悉方式。
于是用我准备的TestWinControl工程写了如下代码。
bin Files文件夹中有100个1~100编号的.bin文档。重新读写后
bin文件夹中生成100个已经去掉最后两个byte的.bin文档。
#include "stdafx.h"#include <afx.h>#include <iostream>using namespace std;CString GetExeDir(){ CString ExePath, ExeDir; TCHAR tempPath[MAX_PATH] = {0}; GetModuleFileName(NULL,tempPath,MAX_PATH); ExePath = tempPath; //NOTICE: 得到的路径最后带 *\* ExeDir = ExePath.Left( ExePath.ReverseFind(_T('\\'))+1) ; return ExeDir;}void WriteBin(CString szPath, unsigned char* data, int size){ FILE* pFile; if (_wfopen_s(&pFile, szPath.GetBuffer() , _T("wb+")) == 0) { fwrite(data, 1, size, pFile); fclose(pFile); szPath.Format(_T("%s write"),szPath); cout << "write size: " << size << endl; }}void ReadBin(CString szPath, unsigned char* data, int size){ FILE* pFile; if (_wfopen_s(&pFile, szPath.GetBuffer() , _T("rb+")) == 0) { fread(data, 1, size, pFile); fclose(pFile); szPath.Format(_T("%s read"),szPath); cout << "read size: " << size << endl; }}int main(){ const int size = 1406; unsigned char data[size] = {0}; memset(data, 0, size); const int wsize = 1404; unsigned char wdata[wsize] = {0}; memset(wdata, 0, wsize); CString exeDir = GetExeDir(); CString readPath; CString writePath; CreateDirectory(exeDir + _T("bin\\"), NULL); CFileFind finder; BOOL bw = finder.FindFile(exeDir + _T("bin Files\\*.bin")); while(bw) { bw = finder.FindNextFile(); if (finder.IsDots()) continue; if (finder.IsDirectory()) continue; CString fileName = finder.GetFileName(); readPath = exeDir + _T("bin Files\\") + fileName; writePath = exeDir + _T("bin\\") + fileName; ReadBin(readPath, data, size); memcpy(wdata, data, wsize); WriteBin(writePath, wdata, wsize); } return 0;}
0 0
- bin文档读写
- 读写bin
- LLT测试 -读写BIN文件
- 文档的读写-单文档
- jacob读写word文档
- VB读写XML文档
- C#读写Excel文档
- TWebbrowser读写HTML文档
- jacob读写word文档
- C#读写XML文档
- XML文档的读写
- 读写txt文档
- VC++读写excel文档
- 读写word文档
- 读写一个XML 文档
- 读写Excel2003文档
- 读写配置文档
- Java 读写 中文文档
- Git命令。
- linux 下 apache启动、停止、重启命令
- 怎么破“完全看不懂”
- 环信3.0版本的集成步骤
- 轻松学Hadoop系列之 - 理清CDH Hadoop集群安装流程
- bin文档读写
- Java Double相加出现的怪事
- iOS-基于AVPlayer的视频播放器代码封装-0-需求分析与框架设计阶段
- python中threading模块详解
- [HSON : HC Script Object Notation] Finish Build 1 On GitHub
- Adobe_Acrobat_XI_Io pdf (可编辑)+破解补丁 安装
- python 文件游标以及 re 中的 match,sub(具体示例)
- Android Wear SDK 中文 ---- 创建表盘服务 [Building a Watch Face Service]
- leetcode112题 题解 翻译 C语言版 Python版