In a Java program, I spawn a new Process
via ProcessBuilder
.
args[0] = directory.getAbsolutePath() + File.separator + program;
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(directory);
final Process process = pb.start();
Then, I read the process standard output with a new Thread
new Thread() {
public void run() {
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}.start();
However, when the process outputs non-ASCII characters (such as 'é'
), the line
has character '\uFFFD'
instead.
What is the encoding in the InputStream
returned by getInputStream
(my platform is Windows in Europe)?
How can I change things so that line
contains the expected data (i.e. '\u00E9'
for 'é'
)?
Edit: I tried new InputStreamReader(...,"UTF-8")
:
é
becomes \uFFFD