我有vc 控制台程序,
用二进制方式读文件,再用二进制方式写文件,我认为这样就是复制,可是结果并非如此,
生成的文件不是unicode了,我想做的是把这个unicode的二进制文件全部读入一个byte数组,,要怎么做呢???为什么都如入的的二进制和我想的不一样,,我把new 和delete改为 malloc 和 free 用BCC32编译有时另外一种情况,,不懂哪。
。。
那个高手给指点 一下,,下面是程序。
// t.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <stdio.h>
typedef struct{
unsigned char a;
unsigned char b;
}UChar;
typedef unsigned long UINT32;
typedef unsigned char byte;
UINT32 getFileSize(FILE *file)
{
     UINT32 r;
     fseek(file, 0, 2);
     r = ftell(file);
     fseek(file, 0, 0);
     return(r);
}
void main(int argc, char* argv[])
{
FILE *fp,*fp2; 
UINT32 filesize;
byte *buff; fp = fopen("worldtime.brx", "rb");
fp2 = fopen("out.brx", "wb+");
filesize = getFileSize(fp);
if(NULL == fp) printf("file open err");
if(NULL == fp2) printf("file open err2");
buff = new byte[filesize];
if(NULL == buff) printf("malloc fail");

fread(buff,1,filesize,fp);
fwrite(buff,1,filesize,fp2);
                     

delete(buff);
fclose(fp);
fclose(fp2);
}
///

解决方案 »

  1.   

    我用printf("%x%x\n",buff[0],buff[1]); 输出为什么是3c,我认为应该是unicode的文件头ff,fe
      

  2.   

    unicode文件不太清楚,不过肯定有文件头吧!你先把文件结构搞懂,再试试看.
      

  3.   

    HANDLE hFile; 
    hFile = CreateFile(lpctstrPath,// open 路径 
    GENERIC_READ,              // open for reading 
    FILE_SHARE_READ,           // share for reading 
    NULL,                      // no security 
    OPEN_EXISTING,             // existing file only 
    FILE_ATTRIBUTE_NORMAL,     // normal file 
    NULL);  
    WCHAR const *sig; 
    DWORD dwLen=0;
    BOOL bRet=::ReadFile(hFile,&sig,2,&dwLen,0);
    if((WCHAR)sig==0xfeff)是unicode
      

  4.   

    关键在于你读/写的时候,是否将字符的unicode编码写入了文件。我怀疑你写入的二进制编码是ANSI格式,而并非UNICODE.
      MultiByteToWideChar()转化为UNiCODE,WideCharToMultiByte()转化为ANSI。
      例如,"你好"的汉字编码 "C4E3 BAC3",但是unicode编码"4F60 597D"