문제

What needs to happen to a string using Java to be an equivalent of vis

: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

다른 팁

For UTF-8 the BOM is: 0xEF, 0xBB, 0xBF

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top