保存属性至xml并读取

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

public class PropertiesDemo04 {
    public static void main(String[] args) {
        Properties pro = new Properties();
        pro.setProperty("BJ", "Beijing");
        pro.setProperty("DJ", "TOKYO");
        pro.setProperty("DB", "oSA");
        File file = new File("E:" + File.separator + "area.xml");
        try {
            pro.storeToXML(new FileOutputStream(file), "AREA INFO");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            pro.loadFromXML(new FileInputStream(file));
        } catch (InvalidPropertiesFormatException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("DJ:" + pro.getProperty("DJ"));
    }
}

上一篇:解决Ubuntu下Sublime Text 3无法输入中文


下一篇:为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录