0

I'm trying to read the flow from the system console but I have some problems with the encoding. As I'm french, my keyboard has some special chars such as 'é', 'è', 'à', etc...

When I put the content of the console into a text area, I got something like that:

Le volume dans le lecteur C s'appelle DisqueC
Le num?ro de s?rie du volume est CE7........
3 fichier(s)           20?229 octets
5 R?p(s)  450?096?623?616 octets libres

It automaticaly replaces special chars by '?' and there is also a problem with the size.

I read the content of the console like that:

BufferedReader stdInput = new BufferedReader(new InputStreamReader(child.getInputStream(), "UTF-8"));
BufferedReader stdError = new BufferedReader(new InputStreamReader(child.getErrorStream(), "UTF-8"));

String line;
byte[] lineBytes;
while ((line = stdInput.readLine()) != null)
{
    lineBytes = line.getBytes("UTF-8");
    buffer.append("\t\t" + new String(lineBytes, "UTF-8") + "\n");
}
stdInput.close();
while ((line = stdError.readLine()) != null)
{
lineBytes = line.getBytes("UTF-8");
buffer.append("\t\t" + new String(lineBytes, "UTF-8") + "\n");
}
stdError.close();

Then the buffer is sent through a socket and I display it like that into a jTextArea:

textArea.append(new String(console_output.getBytes(), "UTF-8"););

So, can anyone tell me why I have this problem with encoding?

Thanks.

1

2 Answers 2

1

If you are doing it on Windows, you should forget that. The default Command Line Encoding ist CP850 which is crap. You can change that for the session but you won't be able to call any batch files.

Try chcp 65001

This will switch to UTF-8. Check this StackOveflow search.

Sign up to request clarification or add additional context in comments.

2 Comments

Even if you use chcp 65001 to change the code page to UTF-8, the console may not show UTF-8 correctly. See stackoverflow.com/questions/10143998/…
Pity, the Windows console is pure crap.
0

In some cases this function will be well:

System.out.println(String.format(Locale.UK, <your String value>, args));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.