Chinaunix首页 | 论坛 | 博客
  • 博客访问: 120923
  • 博文数量: 29
  • 博客积分: 170
  • 博客等级: 入伍新兵
  • 技术积分: 302
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-04 13:48
个人简介

linux 爱好者,java爱好者

文章分类

全部博文(29)

文章存档

2023年(1)

2022年(2)

2020年(3)

2019年(1)

2018年(3)

2017年(8)

2016年(1)

2015年(4)

2014年(2)

2009年(1)

2008年(3)

我的朋友

分类: Java

2017-02-09 12:43:46

java打包后的jar文件访问properties文件

在打包成jar文件时,不要讲properties文件及其目录打包进jar,要放到jar外面。
访问properties的代码:

public DBHelp(){
        Properties properties = new Properties();
        try {
            URI  uri = Paths.get("resource/dblook.properties").toAbsolutePath().toUri();
            System.out.println(uri);
          
            File file = new File(uri);
            properties.load(new java.io.FileInputStream(file));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(DBHelp.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(DBHelp.class.getName()).log(Level.SEVERE, null, ex);
        }

阅读(1856) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~