1.读取全部
File file = new File("C:/Users/Administrator/Desktop/temp/xiaobai.xml");
BufferedReader br= new BufferedReader(new FileReader(file));
String st;
StringBuilder builder = new StringBuilder();
while ((st = br.readLine()) != null){
builder.append(st);
// System.out.println(st);
}
System.out.println(builder);
xml文件
<?xml version="1.0" encoding="UTF-8"?>
<语料 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>张三</name>
<age>19</age>
<gender>男</gender>
<name>里斯</name>
<age>19</age>
<gender>女</gender>
</语料>
打印
"C:\Program Files\Java\jdk1.8.0_221\bin\java.exe"...
<?xml version="1.0" encoding="UTF-8"?>
<语料 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>张三</name>
<age>19</age>
<gender>男</gender>
<name>里斯</name>
<age>19</age>
<gender>女</gender>
</语料>