2013-10-01 20 views
0

如何在調試或從IDE運行progrm時在Eclipse和NetBeans中設置默認字符集。以下函數返回默認字符集系統正在使用的函數。在IDE和命令Promt中設置默認字符集

private static String getDefaultCharSet() { 
    OutputStreamWriter writer = new OutputStreamWriter(new ByteArrayOutputStream()); 
    String enc = writer.getEncoding(); 
    return enc; 
} 

如何讓java在命令提示符運行時使用所需的字符集。

+0

最好是始終指定你想要的字符集的'OutputStreamWriter'構造函數,而不是依賴於默認。 –

回答

0

從eclipse /命令行運行程序時,使用file.encoding設置字符集。 你可以把它作爲參數傳遞給youy程序-Dfile.encoding=whatever

//Set it programatically 
System.setProperty("file.encoding", "UTF-8");