文件在Java工程和 jar包统一处理

default.ini配置文件,希望在代码开发过程中和打成jar包发布过程中都能够读取到。

            File file = new File("default.ini");
            InputStream fis;
            if (file.exists())
            {
                fis = new FileInputStream(file);
            }
            else
            {
                // 定位jar内资源
                fis = this.getClass().getResourceAsStream("/default.ini");
            }
            init(fis);
    private void init(InputStream is)
        throws Exception
    {
        Properties config = new Properties();
        config.load(is); 
         // ......
        IOUtils.closeQuietly(is);
    }

猜你喜欢

转载自blog.csdn.net/qq_16127313/article/details/82920564