对于不同编码的文本文件,简单的判断方法为读取前两个字节: Unicode的前两个字节: 0xFFFE Unicode Big Endian: 0xFEFF UTF8: EFBB ANSI:没格式 wxWidgets样板代码如下: bool SelDrvDlg::IsUnicode(wxString fileName) { FILE *file = fopen(fileName.mb_str(), "r"); if (NULL == file) { return false; } char fileBuf[8] = {0}; size_t st = sizeof(fileBuf); fread(fileBuf, sizeof(char), sizeof(fileBuf), file); fclose(file); if ( (char)fileBuf[0] == (char)0xff ) //check the first byte { return true; } else { return false; } }