2013-10-03 26 views
2

我已經寫在eclipse這個代碼得到一些阿拉伯字,然後打印出來如何閱讀和阿拉伯語寫在Eclipse

public class getString {   
     public static void main(String[] args) throws Exception { 
      PrintStream out = new PrintStream(System.out, true, "UTF-8"); 
      Reader r = new InputStreamReader(System.in, "UTF-8"); 
      char[] str ; 
      str= new char[10]; 
      r.read(str); 
      out.println(str); 

    } 
    } 

但輸出是這樣的:

شیرین

Ø'یرین

任何幫助?

在此先感謝您的關注

+1

是不是'str的[0]'只是一個角色?你如何獲得不止一個角色? –

+0

修復Eclipse中的控制檯編碼爲UTF-8。如果你在Windows上,它不會起作用。 – bmargulies

+0

如果從System.in讀取和寫入到System.out沒有試圖改變編碼會發生什麼? –

回答

7

通過窗口>首選項>常規>工作空間>文本文件編碼只需設置工作區編碼成UTF-8。這也會影響Eclipse控制檯中stdout的編碼。

enter image description here

那麼你也可以僅僅通過更換System.outnew PrintStream(System.out, true, "UTF-8")

+0

感謝您的回答,但它不起作用 – Linda

+1

然後,您的問題是其他地方在目前提供的信息中不可見的。這個對我有用。也許你需要創建一個新的運行配置,以便考慮到編碼的變化。 – BalusC

1

我會嘗試這樣設置:

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8")); 
BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); 

String input = in.readLine(); 
out.write(input); 
out.write("\n"); 
out.flush(); 

這是我用來創建IO處理非拉丁字符。請注意,這沒有自動刷新。

1

由於您使用的是Windows,那麼這就是你如何設置編碼爲UTF-8在eclipse:

1-打開運行對話框>選擇「Java應用程序」>通用標籤> 編碼>其它>「設置它爲UTF-8"

enter image description here

2-打開運行對話框>選擇 「Java應用程序」>參數標籤> VM參數>添加 「-Dfile.encoding = UTF-8」

enter image description here

3-打開窗口菜單>常規>工作空間>文本文件編碼 應設置爲 「UTF-8」

enter image description here

然後你可以運行你的應用程序。

+1

我試過了,但是我又遇到了這個問題 – Linda

+1

你可以去**編輯>設置編碼,然後選擇UTF-8 **,然後進行新的測試? – mabbas