1 package scala_enhance.xml 2
3 import scala.xml.XML 4 import scala.io.Source 5 import jdk.internal.org.xml.sax.InputSource 6 import java.io.FileInputStream 7 import java.io.InputStreamReader 8
9 /**
10 * 讀取與保存xml文檔 11 */
12 object Demo4 { 13 val path = "C:\\Users\\Administrator\\Desktop\\constant.xml"; 14
15 //讀取
16 val x1 = XML.loadFile(path); 17 println(x1); 18
19 //使用java的io
20 val x2 = XML.load(new FileInputStream(path)); 21 println(x2); 22
23 val x3 = XML.load(new InputStreamReader(new FileInputStream(path),"utf-8")); 24 println(x3); 25
26
27 //寫出
28 val newPath = "C:\\Users\\Administrator\\Desktop\\constantXXX.xml"; 29 XML.save(newPath,x3,"utf-8"); 30
31
32 def main(args: Array[String]): Unit = { 33
34 } 35 }