當前位置:首頁 » 編程語言 » 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-09-17 19:00:32 瀏覽:997
php判斷設備 發布:2025-09-17 18:27:53 瀏覽:400
醫院存儲方案 發布:2025-09-17 18:26:38 瀏覽:350
用戶注冊java 發布:2025-09-17 18:23:40 瀏覽:396
centosftp不能上傳 發布:2025-09-17 18:19:15 瀏覽:733
我的世界超平坦生存伺服器 發布:2025-09-17 18:01:06 瀏覽:758
手機只上微信要什麼配置 發布:2025-09-17 17:56:19 瀏覽:694
什麼叫配置高的電腦 發布:2025-09-17 17:53:15 瀏覽:571
php考試系統源碼 發布:2025-09-17 17:52:27 瀏覽:824
打牌的演算法 發布:2025-09-17 17:37:46 瀏覽:174