Properties读取配置文件
来源:互联网 发布:域名怎么购买 编辑:程序博客网 时间:2024/05/17 03:02
impor java.io.*; import java.util.*; public class ReadProperties { public static void main(String[] args) { File pFile = new File("e:\test.properties"); // properties文件放在e盘下(windows) FileInputStream pInStream=null; try { pInStream = new FileInputStream(pFile ); } catch (FileNotFoundException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } Properties p = new Properties(); try { p .load(pInStream ); //Properties 对象已生成,包括文件中的数据 } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } Enumeration enu = p.propertyNames(); //取出所有的key //输出--1 p.list(System.out) ; //System.out可以改为其他的输出流(包括可以输出到文件) //输出--2while( enu .hasMoreElements()) { System.out.print("key="+enu.nextElement()); System.out.print("value="+p.getProperty((String)enu .nextElement())); } } } 读取xml格式的配置文件 test.xml文件ruxi <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties><pre name="code" class="java">impor java.io.*; import java.util.*; public class ReadProperties { public static void main(String[] args) { File pFile = new File("e:\test.properties"); // properties文件放在e盘下(windows) FileInputStream pInStream=null; try { pInStream = new FileInputStream(pFile ); } catch (FileNotFoundException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } Properties p = new Properties(); try { p .load(pInStream ); //Properties 对象已生成,包括文件中的数据 } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } Enumeration enu = p.propertyNames(); //取出所有的key //输出--1 p.list(System.out) ; //System.out可以改为其他的输出流(包括可以输出到文件) //输出--2while( enu .hasMoreElements()) { System.out.print("key="+enu.nextElement()); System.out.print("value="+p.getProperty((String)enu .nextElement())); } } } 读取xml格式的配置文件 test.xml文件ruxi <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <entry key="koo">bar</entry> <entry key="fu">baz</entry> </properties> 读取xml的方法 import java.io.IOException; import java.io.File; import java.io.FileInputStream; import java.util.Properties; public class Test { public static void main(String[] args) { File pFile = new File("e:\test.xml"); // properties文件放在e盘下(windows) FileInputStream pInStream = null; try { pInStream = new FileInputStream(pFile); Properties p = new Properties(); p.loadFromXML(pInStream); p.list(System.out); } catch (IOException e) { e.printStackTrace(); } } }
ntry> <entry key="fu">baz</entry> </properties> 读取xml的方法 import java.io.IOException; import java.io.File; import java.io.FileInputStream; import java.util.Properties; public class Test { public static void main(String[] args) { File pFile = new File("e:\test.xml"); // properties文件放在e盘下(windows) FileInputStream pInStream = null; try { pInStream = new FileInputStream(pFile); Properties p = new Properties(); p.loadFromXML(pInStream); p.list(System.out); } catch (IOException e) { e.printStackTrace(); } } }
0 0
- java 读取properties配置文件
- Java读取properties配置文件
- 读取properties配置文件
- java读取properties配置文件
- java 读取配置文件properties
- 读取.properties配置文件
- java 读取*.properties配置文件
- Java读取properties配置文件
- java 读取配置文件(properties)
- java读取 .properties配置文件
- Properties 读取配置文件
- java读取properties配置文件
- Properties配置文件读取
- spring 读取properties配置文件
- 读取Properties配置文件内容
- 读取.properties配置文件
- birt读取配置文件.properties
- Java读取properties配置文件
- hdoj 1421 搬寝室 【dp 滚动数组优化】
- 欧几里德和扩展欧几里德算法
- Js Javascript 获取Get参数
- 二维码生成 C#
- 防火墙 FAQ
- Properties读取配置文件
- 应届Java小菜鸟初到公司之环境部署
- java调用R语言包(JRI方式),bug记录
- JVM虚拟机---在centos下安装及编译openjdk
- 在Android Studio中进行单元测试和UI测试
- android studio IDE环境里的竖线怎么去掉?
- Android:Service 随记
- PHP页面间参数传递的四种方法详解
- Linux每日学习(二)