What needs to happen to a string using Java to be an equivalent of vi
s
:set nobomb
Assume that BOM
comes from the file I am reading.
What needs to happen to a string using Java to be an equivalent of vi
s
:set nobomb
Assume that BOM
comes from the file I am reading.
Java does not handle BOM properly. In fact Java handles a BOM like every other char.
Found this:
http://www.rgagnon.com/javadetails/java-handle-utf8-file-with-bom.html
public static final String UTF8_BOM = "\uFEFF";
private static String removeUTF8BOM(String s) {
if (s.startsWith(UTF8_BOM)) {
s = s.substring(1);
}
return s;
}
May be I would use apache IO instead:
http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/BOMInputStream.html
UTF8_BOM
is a wrong name. There is nothing in the BOM that links it to UTF-8. On the contrary, UTF-8 does NOT need the BOM, while UTF-16 MAY (and Microsoft has the bad habit of writing UTF-16 files with a BOM, which often get converted to UTF-8 with BOM by bad tools). –
Rainer For UTF-8 the BOM is this sequence of three bytes: 0xEF, 0xBB, 0xBF
© 2022 - 2024 — McMap. All rights reserved.