有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用Java运行时调用aspell程序时出现字符集问题。getRuntime()。执行官

我正在尝试调用linux aspell程序,以便使用Java运行时在Java中进行拼写检查。getRuntime()。exec()。问题是,它似乎与输入/输出字符编码相矛盾。一些输入字在重音字母位置被分成两个字,输出显示为� 对于重音字母。我可以看到aspell可以在命令管道模式下正确拼写检查pt\u 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流字符集编码有问题,但我不知道具体在哪里设置它们


共 (1) 个答案