如何以编程方式正确设置JVM(1.5.x)使用的默认字符编码?
我已经读过-Dfile.encoding=whatever以前用于旧JVM的方法......由于我不会进入的原因,我没有那么奢侈.
我试过了:
System.setProperty("file.encoding", "UTF-8");
Run Code Online (Sandbox Code Playgroud)
并且属性已设置,但它似乎不会导致下面的最终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());
Run Code Online (Sandbox Code Playgroud) 我有以下代码,但我希望它写为UTF-8文件来处理外来字符.有没有办法做到这一点,是否需要有一个参数?
我非常感谢你对此的帮助.谢谢.
try {
BufferedReader reader = new BufferedReader(new FileReader("C:/Users/Jess/My Documents/actresses.list"));
writer = new BufferedWriter(new FileWriter("C:/Users/Jess/My Documents/actressesFormatted.csv"));
while( (line = reader.readLine()) != null) {
//If the line starts with a tab then we just want to add a movie
//using the current actor's name.
if(line.length() == 0)
continue;
else if(line.charAt(0) == '\t') {
readMovieLine2(0, line, surname.toString(), forename.toString());
} //Else we've reached a new actor
else {
readActorName(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码,我想使输出流使用utf-8.基本上我有像é这样的字符é看起来像编码问题.
我见过很多使用的例子......
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(path),"UTF-8");
Run Code Online (Sandbox Code Playgroud)
我目前的代码是......
BufferedWriter out = new
BufferedWriter(new FileWriter(DatabaseProps.fileLocation + "Output.xml"));
Run Code Online (Sandbox Code Playgroud)
是否可以将此对象定义为UTF-8而无需使用OutputStreamWriter?
谢谢,