馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
本文說明將 BIG 5 格式的文件檔,讀取後為 Byte 形式,如何轉換為 UTF-16LE 文字格式輸出。
執行方式程式段說明:
// 讀取檔案
BufferedInputStream bReader = new BufferedInputStream(new FileInputStream(sFile));
// 讀取 tCnt Byte 放入 Buf 0 開始位置
rCnt = bReader.read(Buf, 0, tCnt);
// Byte BIG5 轉為 UTF-16LE
sName = StringUtil.MTByte2Str(Buf, "BIG5", "UTF-16LE");
// Byte 文字轉換(exp: BIG5 轉為 UTF-16LE)
public static String MTByte2Str(byte[] tBuf, String sType, String tType) {
String retStr = null;
try {
// Byte 轉為目前 文字 Type String (BIG5)
retStr = new String(tBuf, sType);
// String 轉為目前 指定文字 Type Byte (UTF-16LE)
byte y[]=retStr.getBytes(tType);
int gCnt = 0;
for (gCnt=0; gCnt<tBuf.length; gCnt++) {
if(0 == y[gCnt])
break;
}
// Byte 轉為目前 指定文字 Type String (UTF-16LE)
retStr = new String(y, 0, gCnt, tType);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return retStr;
}
|

|