Properties相关
生活随笔
收集整理的這篇文章主要介紹了
Properties相关
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties;public class PropertiesUtil {public static final String SAMPLE_XML = "sampleprops.xml";public static final String SAMPLE_PROPERTIES = "sample.properties";public static void main(String[] args) throws Exception{System.out.println("load:");load();System.out.println("loadFromXml:");loadFromXML();printPro();}public static void load() throws Exception{Properties pro = new Properties();pro.load(new FileInputStream(new File("F:/XXX/sample.properties")));pro.list(System.out);}public static void loadFromXML() throws Exception{Properties pro = new Properties();pro.loadFromXML(new FileInputStream(new File("F:/XXX/util/sample.xml")));pro.list(System.out);}public static void printPro() throws Exception{Properties pro = new Properties();pro.put("test_k_01", "test_v_01");pro.put("test_k_02", "test_v_02");pro.store(new FileOutputStream(new File("F:/XXX/test.properties")), "pro");pro.storeToXML(new FileOutputStream(new File("F:/XXX/test.xml")), "xml");} }
?
解析的文件:
sample.properties
foo=bar fu=baz
sample.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>Hi</comment> <entry key="foo">bar</entry> <entry key="fu">baz</entry> </properties>
生成的文件:
test.properties
#pro #Tue Oct 13 20:36:42 CST 2015 test_k_02=test_v_02 test_k_01=test_v_01
?
test.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>xml</comment> <entry key="test_k_02">test_v_02</entry> <entry key="test_k_01">test_v_01</entry> </properties>
?
?
轉載于:https://my.oschina.net/bughope/blog/516795
總結
以上是生活随笔為你收集整理的Properties相关的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创造信用收入 借贷宝颠覆创新普惠金融
- 下一篇: 开源 java CMS - FreeCM