首页 > 技术文章 > jar包读取包内properties文件

zimublog 2018-04-19 15:40 原文

properties位于src目录下

project

    --src

         -----package

         -----test.properties

 

Properties p = new Properties();
//从输入流中读取属性列表(键和元素对)
p.load(DB.class.getClass().getResourceAsStream("/test.properties"));
String testKey = p.getProperty("testKey");

不能这样写

 File file = new File("src/test.properties");

输出路径为会带!   因为是jar包

 

 

java指定编码格式utf-8运行jar

java -Dfile.encoding=utf-8 -jar test.jar

 

推荐阅读