小编典典

使用Java删除BOM字符

java

使用Java等同于vis 的字符串需要发生什么

:set nobomb

假设它BOM来自我正在读取的文件。


阅读 598

收藏
2020-09-28

共1个答案

小编典典

Java无法正确处理BOM。实际上,Java像处理其他所有char一样处理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

2020-09-28