Byte order mark screws up file reading in Java

后端 未结 9 2604
说谎
说谎 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:47

    The Apache Commons IO Library's BOMInputStream has already been mentioned by @rescdsk, but I did not see it mention how to get an InputStream without the BOM.

    Here's how I did it in Scala.

     import java.io._
     val file = new File(path_to_xml_file_with_BOM)
     val fileInpStream = new FileInputStream(file)   
     val bomIn = new BOMInputStream(fileInpStream, 
             false); // false means don't include BOM
    

提交回复
热议问题