Question

I have a weird situation that I can't understand.

 public static void main(String[] args) throws IOException {
    Reader reader = new FileReader("c:/file/UT563984.xml");
    int b = 0;
    while ((b = reader.read()) != -1) {
      System.out.println(b);
    }
  }

When I run this code as a simple small Java program, the output is

255 254 60 0 63 0 120 0 109 0 ......

But, when I run it in a project that has many jars for Spring, SOAP Web Service, Junit etc.., it gives different output -

65533 65533 60 0 63 0 120 0 109 0 .....

As you can see, the BOM is totally wrong.

What is going on here?

Are some jars interfering in the file reading process?

Was it helpful?

Solution

I suggest to read the file with FileInputStream then you will get the bytes as is. FileReader involves converting bytes into chars using default encoding which may be the reason of confusion

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top