0

I have a file with some non-ASCII character like

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

and I have a Java code to read the file

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();
        }
    }
}

In Netbeans those non ASCII are not shown but in Eclipse console those character are displayed as it is. I want to know how Netbeans were able to remove those character as i need to clean up my files for those non ASCII characters.

Thanks

αƞjiβ
  • 3,056
  • 14
  • 58
  • 95

1 Answers1

0

The best way to do this is to read the file as bytes, and then configure a specific CharsetDecoder to remove the bytes you do not want to capture.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263