Skip to content
Advertisement

Byte order mark screws up file reading in Java

I’m trying to read CSV files using Java. Some of the files may have a byte order mark in the beginning, but not all. When present, the byte order gets read along with the rest of the first line, thus causing problems with string compares.

Is there an easy way to skip the byte order mark when it is present?

Advertisement

Answer

EDIT: I’ve made a proper release on GitHub: https://github.com/gpakosz/UnicodeBOMInputStream


Here is a class I coded a while ago, I just edited the package name before pasting. Nothing special, it is quite similar to solutions posted in SUN’s bug database. Incorporate it in your code and you’re fine.

JavaScript

And you’re using it this way:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement