JAVA 解析文本文档头部需要注意点

 1 year ago
source link: https://www.jansora.com/notes/713
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

JAVA 解析文本文档头部需要注意点

UTF-8 BOM 格式下的文本文档解析时第一行的第一个字符是'\uFEFF' 65279, 解析的时候需要注意下

private String[] readTxtSheetHeader() throws IOException {
    String[] line = this.txtFileFp.readLine().split(",");
    // UTF-8 BOM 格式下的文本文档解析时第一行的第一个字符是'\uFEFF' 65279, 需要过滤下
    // https://blog.csdn.net/m0_37721946/article/details/79724511
    if (line.length > 0 && line[0].length() > 0 && 65279 == line[0].charAt(0)) {
        line[0] = line[0].substring(1);
    return line;

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK