簡體   English   中英

像'-'這樣的char替換為'???' 在linux機器上

[英]char like '-' replaced with '???' on linux machine

文件(HTML)內容具有特殊字符,如'-'替換為'???' 在linux機器上。當我在Windows上運行相同的代碼時,它不會替換。

        PrintWriter out = new PrintWriter(file);
        for (String l : lines)
            out.println(l);
        out.close();

我嘗試添加Unicode UTF-16,UTF-8和iso-8859-1無法正常工作

PrintWriter out = new PrintWriter(file, "UTF-16");

在Windows機器上,特殊字符如'-'替換為'–'

先感謝您

有幾個破折號“ –”和“-”。 它們看起來相似,但是具有不同的unicode值。 在源代碼中使用后者。

此處有更多破折號: http : //en.wikipedia.org/wiki/Dash 您的符號是“破折號” U+2013 ,應使用“標准ASCII連字符” U+002D

我通過以與文件相同的編碼方式寫入文件來解決

     InputStreamReader r = new InputStreamReader(new FileInputStream(file));

        // now, write the file again with the changes
        PrintWriter out = new PrintWriter(file, r.getEncoding());
        for (String l : lines)
            out.println(l);
        out.close();

暫無
暫無

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

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