ㄓㄤㄑㄧㄤ

将properties文件放在Jar包并读取

有时候需要在一个library内部打包一个properties文件,包含一些配置信息,而不能部署在外部。

在maven工程里面,将properties文件放在src/main/resources目录下。就会自动打包到classes目录下。

然后在jar包的代码中想要读取这个文件,可以用类似下面的代码:

 

  1. public class Client {  
  2.   
  3.     private final static String NAME = "engine.properties";  
  4.   
  5.     public static Map<String, String> load() throws AppEngineException {  
  6.     InputStream stream = Client.class.getClassLoader().getResourceAsStream(NAME);  
  7.     ...  
  8.     }  
  9. }  



 

一切OK.

转自:http://blog.csdn.net/csfreebird/article/details/7701953

posted @ 2014-10-17 11:48  ㄓㄤㄑㄧㄤ  阅读(407)  评论(0编辑  收藏  举报
哈哈,页脚部分。