質問

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?

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top