我試圖從系統控制檯讀取流程,但是我在編碼方面存在一些問題。 因爲我是法國人,所以我的鍵盤有一些特殊的字符,例如'é','è','à'等等......Java - 編碼字符串
當我把控制檯的內容放到一個文本區域時,這樣的事情:
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
它automaticaly取代特殊字符的'?'而且尺寸也有問題。
我讀的控制檯類似的內容:緩衝區是通過套接字發送
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();
然後我展示它就像進入一個JTextArea:
textArea.append(new String(console_output.getBytes(), "UTF-8"););
所以,任何人都可以告訴我爲什麼我的編碼有這個問題?
謝謝。
這可能是相關的:http://stackoverflow.com/questions/2914069/how-to-add-diffrent-characterset-support-for- jtextarea – mcfinnigan 2012-04-18 09:39:43