歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Java讀取配置Properties文件

Java讀取配置Properties文件

日期:2017/3/1 10:10:57   编辑:Linux編程

config.properties:

  1. author=xmq
  2. user=xmq
  3. copyright=2012-2015

java文件:

  1. import java.io.FileInputStream;
  2. import java.util.Enumeration;
  3. import java.util.Properties;
  4. class PropTest {
  5. public static void main(String[] args) {
  6. Properties pps=new Properties();
  7. try {
  8. pps.load(new FileInputStream("config.properties"));
  9. Enumeration enum = pps.propertyNames();
  10. while (enum.hasMoreElements()) {
  11. String strKey = (String) enum1.nextElement();
  12. String strValue = pps.getProperty(strKey);
  13. System.out.println(strKey + "=" + strValue);
  14. }
  15. } catch (Exception e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. }

Copyright © Linux教程網 All Rights Reserved