当我执行Build项目时,3字节UTF-8序列的字节2无效

时间:2015-07-15 22:07:07

标签: java xml utf-8

项目链接:https://github.com/GunB/eExcelParser 我正在尝试更改基于metadata.xml的XML,并且当我运行Netbeans进行编译时它正常工作但是当我创建Clean和Build版本时它会抛出Invalid byte 2 of a 3-byte UTF-8 sequence ......我无法理解为什么

我使用此代码来读取XML文件

File fXmlFile = new File(strBase);
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        doc = dBuilder.parse(fXmlFile);

我使用的库是POIGuava,POI附带的XMLBeans和dom4j

该项目也在发送此警告:

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Warning: Setting Codebase manifest attribute to '*' due to current JNLP Codebase. Set manifest.custom.codebase property to override the non-secure value '*'.

2 个答案:

答案 0 :(得分:0)

我尝试了以下内容,它运行正常:

public static void main(String[] args) throws Exception{
    DocumentBuilderFactory Factory;
    Factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = Factory.newDocumentBuilder();
    Document doc = parser.parse("https://raw.githubusercontent.com/GunB/eExcelParser/develop/metadata.xml");
}

可能是你没有妥善保存文件; 我还使用curl保存metada.xml

curl -O https://raw.githubusercontent.com/GunB/eExcelParser/develop/metadata.xml

当我解析本地文件时,它也可以正常工作

答案 1 :(得分:0)

XML文件似乎被转换为错误的单字节编码。检查是否使用Reader/Writer/String.getBytes/new String始终指定了charset。切勿使用FileReader/FileWriter