爪哇一角

共同探讨STRUTS#HIBERNATE#SPRING#EJB等技术
posts - 3, comments - 6, trackbacks - 0, articles - 99
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

properties文件读入

Posted on 2009-06-12 11:20 非洲小白脸 阅读(155) 评论(0)  编辑  收藏 所属分类: 其他资源
package test;

import java.util.*;
import java.io.*;


public class test {

 
public String getPara(String fileName) {
  Properties prop 
= new Properties();
  
try {
   InputStream is 
= getClass().getResourceAsStream(fileName);
   prop.load(is);
   
if (is != null)
    is.close();
  }
 catch (Exception e) {
   System.out.println(e 
+ "file " + fileName + " not found");
  }

  
return prop.getProperty("db");
 }


 
public static void main(String[] args) {
  test test 
= new test();
  System.out.println(test.getPara(
"db.properties"));
 }

}


java文件同级目录下建立db.properties,
内容  db=123445


只有注册用户登录后才能发表评论。


网站导航: