當前位置:首頁 » 編程語言 » javaunicode中文

javaunicode中文

發布時間: 2023-07-28 07:07:38

A. 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);
}
}

B. 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漢字。

C. java中如何取得中文如「中國」在unicode編碼中的表示串

public class Demo
{
public static void main(String[] args)
{
String str="例子";
//數組bm保存的就是"例子"的Unicode代碼點(10進制)
int[] bm=new int[str.length()];

for(int i=0;i<str.length();i++)
{
bm[i]=str.codePointAt(i);
System.out.print(""+bm[i]+" ");
}
}
}

D. JAVA程序,從鍵盤輸入漢字,並將漢子轉換為相應的unicode編碼,怎麼寫啊

上代碼:

importjava.util.Scanner;

publicclassMain{
publicstaticvoidmain(String[]args){
Scannersc=newScanner(System.in);
System.out.println("請輸入漢字:");
Stringinput=sc.nextLine();
塌漏if(input.length()==0){
System.out.println("輸入錯誤");
return;
}

System.out.println("漢字轉unicode結果:");
char[]chars=input.toCharArray();
for(inti=0;i<chars.length;i++){
Stringunicode=Integer.toHexString(chars[i]);
if(unicode.length()<=2){
團哪爛//不足四位前面加0補齊
緩激unicode="00"+unicode;
}
unicode="\u"+unicode;

System.out.println(chars[i]+":"+unicode);
}
}
}

E. 編寫JAVA程序輸出中文字的unicode編碼

我寫的,你試試,你可以把它改寫成循環的,可以一直把字元的Unicode輸出,完善後發給我哈:
import java.io.*;
public class FindUnicode {
public static void main(String[] args) throws IOException{
InputStreamReader read = new InputStreamReader (System.in);
int ch = read.read();
System.out.print("\\u"+Integer.toHexString(ch));
read.close();
}
}

F. java 中常用漢字 的unicode 碼范圍是多少到多少

常用漢字 的unicode 碼范圍是:u4e00-u9fa5,下面一個例子是把中英文文檔中的漢字提取出來的簡單例子:

publicclassDrawEnglish
{
privatestaticStringdraw(Stringcontent)
{
StringBufferenglish=newStringBuffer();

Stringregex="[u4e00-u9fa5。,?」「《》:!——-、]";
Patternpattern=Pattern.compile(regex);
Matchermatcher=pattern.matcher(content);
while(matcher.find())
{
Stringtemp=matcher.group();
english.append(temp);
}
returnenglish.toString();
}
publicstaticvoiddrawEnglish(Stringpath)
{
FileInputStreamfr;
BufferedReaderbr;

FileWriterfw;
BufferedWriterbw=null;
try
{
fr=newFileInputStream(path);
br=newBufferedReader(newInputStreamReader(fr,"gb2312"));
fw=newFileWriter("new1.txt");
bw=newBufferedWriter(fw);
Stringstr=null;
StringBuffersb=newStringBuffer();
while((str=br.readLine())!=null)
{
sb.append(str+" ");
}
Stringtemp=draw(sb.toString());
bw.write(temp);

}catch(FileNotFoundExceptione)
{
e.printStackTrace();
}catch(IOExceptione)
{
e.printStackTrace();
}
finally
{
try
{
if(bw!=null)bw.close();
}catch(IOExceptione)
{
e.printStackTrace();
}
}
}
publicstaticvoidmain(String[]args)
{
drawEnglish("draw1.txt");
}
}
熱點內容
防盜鎖編程 發布:2025-02-07 15:31:33 瀏覽:858
安卓如何快速選擇圖片 發布:2025-02-07 15:30:43 瀏覽:466
硬體組態為什麼不能編譯 發布:2025-02-07 15:30:43 瀏覽:40
紅帆oa伺服器地址查詢 發布:2025-02-07 14:31:41 瀏覽:657
文本框腳本圖片 發布:2025-02-07 14:23:28 瀏覽:231
少兒編程c語言 發布:2025-02-07 14:22:50 瀏覽:218
一階低通濾波器c語言 發布:2025-02-07 14:22:37 瀏覽:852
電腦的東西為什麼粘貼不到伺服器 發布:2025-02-07 14:21:04 瀏覽:197
手機脫模解壓視頻 發布:2025-02-07 14:20:18 瀏覽:473
密碼多少密碼多少密碼多少密碼 發布:2025-02-07 14:07:30 瀏覽:857