设置默认的Java字符编码?
如何以编程方式正确设置JVM(1.5.x)使用的默认字符编码?
我读过-Dfile.encoding=whatever曾经是老年JVM的选择.。我没有那种奢侈,因为我不愿意进入。
我试过:System.setProperty("file.encoding", "UTF-8");
属性将被设置,但它似乎不会导致下面的getBytes最后调用使用UTF 8: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());