国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

java big5到gb2312的編碼轉換

2020-07-27 21:42:13
字體:
來源:轉載
供稿:網友
package com.Big5ToUTF8;
import java.io.*;
public class Big5Tran {
private static final String tabFile ="bg-gb.tab";
private static byte[] data;
static{
try{
FileInputStream fis =new FileInputStream(tabFile);
int len =fis.available();
data =new byte[len];
fis.read(data);
fis.close();
}catch(Exception ex){
ex.printStackTrace();
System.exit(1);
}
}
/**
*取得BIG5漢字big在data中的偏移
*/
private static int indexOf(int big){
int high =(big>>>8)&0xff;
int low =big&0xff;
high -= 0xa1;
if(low<=0x7e) low -= 0x40;
else low -= (0xa1 -0x7e -1) +0x40;
return 2*(high*157+low);
}
/**
*將保存在bs數字中的big5編碼的字符串數據轉換成gb2312編碼的數據
*注意:此方法將更改原先存儲的數據
*@param bs 需要轉換的以big5編碼的字符串數據
*@return bs 經過轉換的數據,保存在參數中的byte數組中
*/
public static byte[] translateBig5ToGb(byte[] bs){
int index =0;
while(index<bs.length){
int high =bs[index]&0xff;
if(high>=0xa1&&high<=0xfe){
index ++;
if(index>=bs.length) break;
int low =bs[index]&0xff;
if(low<0x40||low>0xfe) continue;
if(low>0x7e&&low<0xa1) continue;
int offset =indexOf((high<<8)|low);
bs[index-1] =data[offset];
bs[index ] =data[offset+1];
index++;
}
else index++;
}
return bs;
}
public static String translateBig5ToGb(String big){
String result =null;
try{
byte[] bs =big.getBytes("big5");
bs =translateBig5ToGb(bs);
result =new String(bs,"gb2312");
}catch(Exception e){
}
return result;
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黑龙江省| 漾濞| 阜康市| 东城区| 手机| 马公市| 金门县| 山西省| 永兴县| 秦安县| 含山县| 苍溪县| 临朐县| 通海县| 清涧县| 徐闻县| 巴彦县| 宁蒗| 称多县| 洪雅县| 梨树县| 云龙县| 北票市| 大悟县| 拜城县| 商城县| 儋州市| 合川市| 盐源县| 奉新县| 启东市| 抚顺市| 平江县| 平乐县| 胶州市| 平远县| 卓尼县| 曲水县| 岗巴县| 惠东县| 新昌县|