相关疑难解决方法(0)

如何在Java中找到未关闭的I/O资源?

许多I/O资源,在Java中,如InputStream和OutputStream需要所讨论的,要当他们与完成关闭这里.

如何搜索我的项目中没有关闭此类资源的地方,例如这种错误:

private void readFile(File file) throws IOException {
    InputStream in = new FileInputStream(file);
    int nextByte = in.read();
    while (nextByte != -1) {
        // Do something with the byte here
        // ...
        // Read the next byte
        nextByte = in.read();
    }
    // Oops! Not closing the InputStream
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了一些静态分析工具,如PMD和FindBugs,但是他们没有将上面的代码标记为错误.

java io resources static-analysis

16
推荐指数
3
解决办法
7791
查看次数

标签 统计

io ×1

java ×1

resources ×1

static-analysis ×1