使用 Java 的字符串需要发生什么等效于 vi
:set nobomb
假设BOM
来自我正在读取的文件。
Java 不能正确处理 BOM。事实上,Java处理BOM就像处理其他字符一样。
发现这个:
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;
}
也许我会改用 apache IO:
http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/BOMInputStream.html
对于 UTF-8,BOM 为:0xEF、0xBB 0xBF