Eclipse控制台与Netbeans控制台

时间:2014-09-20 18:02:00

标签: java eclipse netbeans ide non-ascii-characters

我有一个带有非ASCII字符的文件,如

set myval;[2K[DESC[DESC[D

我有一个Java代码来读取文件

public static void main(String[] args) {
    BufferedReader br = null;

    try {

        String sCurrentLine;

        br = new BufferedReader(new FileReader("output.txt"));

        while ((sCurrentLine = br.readLine()) != null) {
            System.out.println(sCurrentLine);
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null) {
                br.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

在Netbeans中,未显示非ASCII,但在Eclipse控制台中,这些字符按原样显示。 我想知道Netbeans如何删除这些字符,因为我需要清理那些非ASCII字符的文件。

谢谢

1 个答案:

答案 0 :(得分:0)

执行此操作的最佳方法是将文件作为字节读取,然后配置特定的CharsetDecoder以删除您不想捕获的字节。