註冊 登錄
Android 台灣中文網 返回首頁

jianrupan的個人空間 https://apk.tw/?1180935 [收藏] [複製] [分享] [RSS]

日誌

取讀 BIG5 碼檔案 轉換成 UTF-16LE 文字格式輸出

已有 282 次閱讀2020-5-11 17:15 |個人分類:軟體應用| 取讀, 檔案, 換成, UTF-16LE, 文字

本文說明將 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;
}


路過

雞蛋

鮮花

握手

雷人

評論 (0 個評論)

facelist

您需要登錄後才可以評論 登錄 | 註冊