Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文件流未关闭会不会有问题 #422

Open
ls9527 opened this issue May 11, 2020 · 0 comments
Open

文件流未关闭会不会有问题 #422

ls9527 opened this issue May 11, 2020 · 0 comments

Comments

@ls9527
Copy link

ls9527 commented May 11, 2020

在代码 com.baidu.disconf.client.support.utils.ConfigLoaderUtils#loadWithTomcatMode
没有关闭文件流, 虽然只打开一次. 但是这样写会不会还是不妥

 private static Properties loadWithTomcatMode(final String propertyFilePath)
            throws Exception {

        Properties props = new Properties();

        try {

            // 先用TOMCAT模式进行导入
            // http://blog.csdn.net/minfree/article/details/1800311
            // http://stackoverflow.com/questions/3263560/sysloader-getresource-problem-in-java
            URL url = ClassLoaderUtil.getLoader().getResource(propertyFilePath);
            URI uri = new URI(url.toString());
            props.load(new InputStreamReader(new FileInputStream(uri.getPath()), "utf-8"));

        } catch (Exception e) {

            // http://stackoverflow.com/questions/574809/load-a-resource-contained-in-a-jar
            props.load(new InputStreamReader(ClassLoaderUtil.getLoader().getResourceAsStream(propertyFilePath),
                    "utf-8"));
        }
        return props;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant