public static String xmlTojsonString(String path) throws JSONException,IOException {
FileInputStream FileData = new FileInputStream(path);
BufferedInputStream data = new BufferedInputStream(FileData);
String xml = IOUtils.toString(data);
JSONObject xmlJSONObj = XML.toJSONObject(xml);
return xmlJSONObj.toString();
}
public static void main(String[] args) throws Exception {
String path = "F://XXXX.XML";//文件路径地址
String string = xmlTojsonString(path);
System.out.println(string);
}
org.json需要两个jar包,一个org.json另一个是commons-io;
jar包路径:https://download.csdn.net/download/fenghuayihe/12509309
原博主地址:https://blog.csdn.net/a532672728/article/details/76312475