簡體   English   中英

如何在Java中讀取特殊字符

[英]How to read special characters in java

當我嘗試以Java讀取此文本時,我將文本存儲在以UTF-8 o|▰╹ェ╹|ツ end (◕□◕✿) end ┐(❛△❛;)編碼的文本文件中像這樣?o|??ェ?|ツ end (?□??) end ┐(?△?;)我什至試圖用Unicode編碼,但是仍然得到相同的文本,這是我的代碼來打印文件

File fileDir = new File("src/mycharacters.txt");

BufferedReader reader = new BufferedReader(new InputStreamReader(
        new FileInputStream(fileDir), "UTF-8"));
String myText = null;
String line = null;
while ((line = reader.readLine()) != null) {
    myText = line;
}

System.out.print(myText);  

您的閱讀很好。 你的寫作是問題所在。 AFAIK System.out具有非UTF編碼。 嘗試將其包裝在PrintStreamPrintWriter

niceOut = new PrintStream(System.out, true, "UTF-8");

編輯:哦,等等,也許@ MathSquared11235實際上是正確的-我的確在您的輸出中看到了ツ,它應該表示UTF輸出。 所以...字體。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM