Byte order mark screws up file reading in Java

后端 未结 9 2498
说谎
说谎 2020-11-22 02:55

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 r

9条回答
  •  无人及你
    2020-11-22 03:27

    To simply remove the BOM characters from your file, I recomend using Apache Common IO

    public BOMInputStream(InputStream delegate,
                  boolean include)
    Constructs a new BOM InputStream that detects a a ByteOrderMark.UTF_8 and optionally includes it.
    Parameters:
    delegate - the InputStream to delegate to
    include - true to include the UTF-8 BOM or false to exclude it
    

    Set include to false and your BOM characters will be excluded.

提交回复
热议问题