導航:首頁 > 編程語言 > javaunicode轉中文

javaunicode轉中文

發布時間:2022-06-08 19:45:37

java讀取含有unicode編碼的文件內容,並轉換成漢字

可以通過BufferedReader 流的形式進行流緩存,之後通過readLine方法獲取到緩存的內容。

BufferedReader bre = null;
try {
String file = "D:/test/test.txt";
bre = new BufferedReader(new FileReader(file));//此時獲取到的bre就是整個文件的緩存流
while ((str = bre.readLine())!= null) // 判斷最後一行不存在,為空結束循環
{
System.out.println(str);//原樣輸出讀到的內容(unicode會自動轉換為中文的)
};
備註:unicode不需要轉換的,直接輸出即可,會自動變成中文,如:
System.out.println("\u0061\u0062\u6c49\u5b57");
結果就是:ab漢字。

② 找一個能將JAVA代碼中Unicode編碼為字元集轉換為漢字的小軟體

利用JDK中自帶的native2ascii工具就很好

如果是在項目中,可以直接拷貝%JDK%/bin下native2ascii.exe至項目根目錄,然後類中這樣調用即可
中文轉UNICODE(srcFileName為中文文件路徑)
StringBuffer tempSb = new StringBuffer();
Process p = Runtime.getRuntime().exec(
"native2ascii "+srcFileName);
InputStreamReader child_in = new InputStreamReader(p
.getInputStream());
int c;
while ((c = child_in.read()) != -1) {
tempSb.append((char) c);
}
System.out.println(tempSb);

UNICODE轉中文(srcFileName為UNICODE文件路徑)
StringBuffer tempSb = new StringBuffer();
Process p = Runtime.getRuntime().exec(
"native2ascii -reverse "+srcFileName);
InputStreamReader child_in = new InputStreamReader(p
.getInputStream());
int c;
while ((c = child_in.read()) != -1) {
tempSb.append((char) c);
}
System.out.println(tempSb);

③ java如何把以unicode編碼形式的字元串變成編碼前的形式

不用轉,直接輸出結果即可,系統會自動轉換。舉例:

System.out.println("u0061u0062u6c49u5b57");

結果就是:ab漢字。

④ java把unicode還原成漢字

這個本來就是unicode的,按unicode的來讀才行。
FF FE 開頭是unicode的標志

public class ReadUnicode {
public static void main(String[] args) throws Exception{
String encoding = "Unicode";
String txtFilePath = "ReadUnicode321.txt";//
String tmpLineVal;
InputStreamReader read = new InputStreamReader(new FileInputStream(txtFilePath), encoding);
BufferedReader bufread = new BufferedReader(read);
while((tmpLineVal = bufread.readLine())!=null){
System.out.println(tmpLineVal);
}
bufread.close();
read.close();
}
}

⑤ java 將字元串中含有unicode 轉成中文!

publicclassConvert
{
(Stringasciicode)
{
String[]asciis=asciicode.split("\\u");
StringnativeValue=asciis[0];
try
{
for(inti=1;i<asciis.length;i++)
{
Stringcode=asciis[i];
nativeValue+=(char)Integer.parseInt(code.substring(0,4),16);
if(code.length()>4)
{
nativeValue+=code.substring(4,code.length());
}
}
}
catch(NumberFormatExceptione)
{
returnasciicode;
}
returnnativeValue;
}

publicstaticvoidmain(String[]args)
{
Stringstr=""JWHQK_JWQC":""";
Stringresult=ascii2native(str);
System.out.println(result);
}
}

⑥ java中如何在中文字元和unicode編碼之間進行轉換

可以這樣來重構字元串new String(「XXX".getByte(),」UTF-8「);後面加上編碼方式

⑦ 用java如何把unicode碼轉成漢字

java中將unicode碼轉換成漢字的方式是直接使用string類型,列印即可:

Stringascii="u4f01u4e1a";//這兩個unicode碼就是企業的
System.out.println(ascii);//列印出來

運行結果:

企業

Unicode只有一個字元集,中、日、韓的三種文字佔用了Unicode中0x3000到0x9FFF的部分 Unicode目前普遍採用的是UCS-2,它用兩個位元組來編碼一個字元, 比如漢字"經"的編碼是0x7ECF,注意字元編碼一般用十六進制來 表示,為了與十進制區分,十六進制以0x開頭,0x7ECF轉換成十進制 就是32463,UCS-2用兩個位元組來編碼字元,兩個位元組就是16位二進制, 2的16次方等於65536,所以UCS-2最多能編碼65536個字元。

⑧ java 中如何將unicode字元集轉換成漢字

我這eclipse自動把它轉中文了。。你看下這個。
http://blog.csdn.net/shigang_xing/article/details/8263728

⑨ 用java如何把unicode碼轉成漢字

Java中字元和字元串都採用的是Unicode編碼;漢字能夠直接表示;不需要轉換
可以測試一下
public
class
Unicode
2Ch
z
{
public
static
void
main(String[]
args)
{
System.out.print(cc);}}直接輸出:保

⑩ 如何利用java把文件中的Unicode字元轉換為漢字

Java中字元和字元串都採用的是Unicode編碼;漢字能夠直接表示;不需要轉換 可以測試一下public class Unicode2Chz {
public static void main(String[] args) {
String cc="\u4fdd";
System.out.print(cc);
}} 直接輸出:保

閱讀全文

與javaunicode轉中文相關的資料

熱點內容
信號分析pdf 瀏覽:925
暴力刪除命令 瀏覽:801
qt如何編譯加快速度 瀏覽:903
php添加數據sql語句 瀏覽:717
免費的小說app有什麼 瀏覽:405
螺桿壓縮機進氣閥動畫 瀏覽:651
兩台伺服器如何做負載均衡 瀏覽:227
程序員的工資是漲的嗎 瀏覽:813
視頻存儲伺服器可以干什麼 瀏覽:463
創建文件夾安裝失敗怎麼回事 瀏覽:832
程序員高考隔了幾年 瀏覽:822
雲伺服器是哪一層 瀏覽:22
jit編譯器的jit什麼意思 瀏覽:330
我想清理手機中空白文件夾 瀏覽:976
電腦e盤文件夾刪不掉怎麼辦 瀏覽:607
外圓凹圓弧編程 瀏覽:461
html5編程題 瀏覽:839
乾燥機製冷壓縮機一開就跳動 瀏覽:388
吉林壓縮空氣流量監測 瀏覽:618
根據地址獲取經緯度php 瀏覽:13