如何以编程方式正确设置JVM (1.5.x)使用的默认字符编码?
我读到过,-Dfile.encoding=whatever曾经是较旧的JVM的首选。我没有那种奢侈的东西,因为我不想说。
我试过了:
System.setProperty("file.encoding", "UTF-8");并且设置了该属性,但它似乎不会导致下面的最终getBytes调用使用UTF8:
System.setProperty("file.encoding", "UTF-8");
byte inbytes[] = new byte[1024];
FileInputStream fis = new FileInputStream("response.txt");
fis.read(inbytes);
FileOutputStream fos = new FileOutputStream("response-2.txt");
String in = new String(inbytes, "UTF8");
fos.write(in.getBytes());发布于 2021-11-05 06:36:49
在启动应用程序时设置jvm参数帮助我解决了这个问题。java -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8。
file.encoding=UTF-8 -这有助于在文件中包含Unicode字符。
sun.jnu.encoding=UTF-8 -这有助于将Unicode字符用作文件系统中的文件名。
https://stackoverflow.com/questions/361975
复制相似问题