Perhaps your file has a BOM (Byte Order Mark) at the beginning? Look at it with a hex editor to find out. And if so, skip over it before trying to use the contents of the file.
Sai Narasimha Reddy
Joined: Dec 13, 2006
why doesn't java filter that BOM before giving me the file contents??....i've read the file using "utf-8" character encoding only.....
did anybody face the same problem??
is there any way out of this without i having to ignore the BOM manually??.....does this problem occur only in windows or it occurs in linux also??. If it doesn't occur in linux then how to make my code portable??
Well, it doesn't. And no, you aren't the only one in the world to experience this problem. And I expect it's the same in Unix as it is in Windows, although it wouldn't be that hard to just try it if that wasn't just a rhetorical question.
If you know in advance that there's going to be a BOM then it's just a couple of lines of code to skip over it. If you don't, it's a little bit more complicated (and a PushbackInputStream can help).