Question

Using the same project and text file as here: Java.NullPointerException null (again) the program is outputting the data but with . To put you in the picture:

This program is a telephone directory, ignoring the first "code" block, look at the second "code" block on that link, that is the text file with the entries. The program outputs them as it should but it is giving  at the beginning of the entries read from the text file ONLY.

Any help as to how to remove it? I am using Buffered Reader with File Reader in it. Thanks in advanced.

  • Encoding of Text File: UTF-8
  • Using Java 7
  • Windows 7
Was it helpful?

Solution

Does the read in textfile uses UTF-8 with BOM? It looks like BOM signs: "" http://en.wikipedia.org/wiki/Byte_order_mark

Are you runnig Windows? Notepad++ sould be able to convert. If using linux or the VI(M) you can use ":set nobomb"

OTHER TIPS

I suppose your input file is encoded in UTF-8 with BOM.

You can either save your input file without a BOM, or handle this in Java.

The thing one might want to do here is to use an InputStreamReader with appropriate encoding. Sadly, that's not possible. The thing is, Java assumes that an UTF-8 encoded file has no BOM, so you have to handle that case manually.

A quick hack would be to check if the first three bytes of your file are 0xEF, 0xBB, 0xBF, and if they are, ignore them.

For a more sophisticated example, have a look at the UnicodeBOMInputStream class in this answer.

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