Java Runtime.getRuntime().exec() を使用して、Java で pt_BR スペルチェック用の Linux aspell プログラムを呼び出そうとしています。問題は、入力/出力文字エンコーディングで問題が発生しているように見えることです。一部の入力単語はアクセント文字の位置で 2 つの単語に分割され、出力はアクセント文字の � で表示されます。aspell がコマンド パイプライン モードで pt_BR を正しくスペル チェックできることがわかります。aspell をセットアップするためのコードは次のとおりです。
String[] aspellCommand = new String[4];
aspellCommand[0] = "aspell";
aspellCommand[1] = "-a";
aspellCommand[2] = "--keymapping=ispell";
aspellCommand[3] = "--lang=pt_BR";
String[] envArray = new String[0];
process = Runtime.getRuntime().exec(aspellCommand, envArray);
System.out.println(Charset.defaultCharset()); /utf-8
InputStreamReader ir = new InputStreamReader(process.getInputStream(), "utf-8");
OutputStreamWriter or = new OutputStreamWriter(process.getOutputStream(), "utf-8");
aspellOutputStream = new BufferedReader(ir);
aspellInputStream = new PrintWriter(or,true);
System.out.println(ir.getEncoding()); /utf-8
System.out.println(or.getEncoding()); /utf-8
入力を aspell にフィードするコード:
aspellInputStream.println(misSpelledWord);
aspell から読み取るコード:
String line = aspellOutputStream.readLine();
IO ストリームの文字セットのエンコーディングに問題があると思われますが、正確に設定する場所がわかりません。