4 个解决方案
#1
文件是在磁盘中已经存在的文件
#2
不管什么文件,归根结底不都是“二进制文件”吗!!!
DOS命令:
ren *.txt *.dat
#3
Dim d() As Byte
d = "你好" & vbCrLf & Now & vbCrLf & " 今天不开心"
Open "c:\二进制测试.txt" For Binary As #1
Put #1, , d
Close #1
测试看看,我不知道怎么读哦
#4
仅供参考,尽管不是VB6:
#include <stdio.h>
#include <string.h>
#include <conio.h>
FILE *fi,*fo;
int r;
unsigned int n,c;
long offset;
//-------------------------------------------------------
void main(int argc,char *argv[])
{
if (argc<3) {
cprintf("Hex2Bin srcfile desfile");
return;
}
if ((fi=fopen(argv[1],"rb"))==NULL) {
cprintf("Can not find file %s",argv[1]);
return;
}
if ((fo=fopen(argv[2],"wb"))==NULL) {
fclose(fi);
cprintf("Can not create file %s",argv[2]);
return;
}
n=0;
while (1) {
offset=ftell(fi);
r=fscanf(fi,"%2x",&c);
if (EOF==r) break;//
if (1==r) {
fputc(c,fo);
n++;
} else {//0==r
fseek(fi,offset,SEEK_SET);//因为VC6的Release版及其VC7,8,9,10,...版的fscanf未按约定保持offset不变,所以此处必须恢复offset
r=fgetc(fi);
if (EOF==r) break;//
}
}
fcloseall();
cprintf("OK to Hex2Bin %d bytes.",n);
}
#1
文件是在磁盘中已经存在的文件
#2
不管什么文件,归根结底不都是“二进制文件”吗!!!
DOS命令:
ren *.txt *.dat
#3
Dim d() As Byte
d = "你好" & vbCrLf & Now & vbCrLf & " 今天不开心"
Open "c:\二进制测试.txt" For Binary As #1
Put #1, , d
Close #1
测试看看,我不知道怎么读哦
#4
仅供参考,尽管不是VB6:
#include <stdio.h>
#include <string.h>
#include <conio.h>
FILE *fi,*fo;
int r;
unsigned int n,c;
long offset;
//-------------------------------------------------------
void main(int argc,char *argv[])
{
if (argc<3) {
cprintf("Hex2Bin srcfile desfile");
return;
}
if ((fi=fopen(argv[1],"rb"))==NULL) {
cprintf("Can not find file %s",argv[1]);
return;
}
if ((fo=fopen(argv[2],"wb"))==NULL) {
fclose(fi);
cprintf("Can not create file %s",argv[2]);
return;
}
n=0;
while (1) {
offset=ftell(fi);
r=fscanf(fi,"%2x",&c);
if (EOF==r) break;//
if (1==r) {
fputc(c,fo);
n++;
} else {//0==r
fseek(fi,offset,SEEK_SET);//因为VC6的Release版及其VC7,8,9,10,...版的fscanf未按约定保持offset不变,所以此处必须恢复offset
r=fgetc(fi);
if (EOF==r) break;//
}
}
fcloseall();
cprintf("OK to Hex2Bin %d bytes.",n);
}