jar包读取包内properties文件

  • Post author:
  • Post category:其他


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

转载于:https://www.cnblogs.com/zimublog/p/8857033.html