我正在尝试通过控制台读取一些数据并将其写入文件。当来自控制台的数据包含变音字符时,我遇到了问题。它打印出'?而不是变音符号。请在下面找到我的代码。有人可以帮帮我吗
String cmd = "cmd /C si viewproject"+ cmdLine+" --recurse --fields=indent,name --project="+name;
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line = null;
File filename = new File(System.getProperty("java.io.tmpdir"),
"Project" + ".tmp");
OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(filename), Charset.forName("UTF-8").newEncoder());
while ((line = in.readLine()) != null) {
osw.write(line);
osw.write("\n");
}
osw.close();