如何以编程方式正确设置JVM(1.5.x)使用的默认字符编码?
我已经读到,-Dfile.encoding=whatever
曾经是老JVM的 Select .我没有那种奢侈,因为我不想进go .
我试过了:
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());