• 保存属性至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"));
        }
    }

  • 相关阅读:
    pat 1034 Head of a Gang (30分)
    pta坑点
    Devc++ 编译 c++11
    Invitation Cards dijkstra法
    Cube Stacking
    畅通工程
    蚂蚁上树
    洛谷 P1439 【模板】最长公共子序列
    Recursive sequence
    A Simple Math Problem
  • 原文地址:https://www.cnblogs.com/vonk/p/3961341.html
Copyright © 2020-2023  润新知