Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
eclipse java资源泄漏_Java_Eclipse - Fatal编程技术网

eclipse java资源泄漏

eclipse java资源泄漏,java,eclipse,Java,Eclipse,Eclipse java警告:资源泄漏:“未分配的可关闭值”从未关闭 try(FileChannel f = new RandomAccessFile(new File(p),"rw").getChannel();){} 泄漏在哪里?资源是随机访问文件。您正在对此对象执行新操作,但您没有将其存储到任何变量中,因此您永远无法将其关闭randomAccesFile.close()。您可以安全地忽略此操作 因为FileChannel也是可关闭的FileChannel::close也会关闭底层流。Ra

Eclipse java警告:资源泄漏:“未分配的可关闭值”从未关闭

try(FileChannel f = new RandomAccessFile(new File(p),"rw").getChannel();){}

泄漏在哪里?

资源是随机访问文件。您正在对此对象执行新操作,但您没有将其存储到任何变量中,因此您永远无法将其关闭randomAccesFile.close()。

您可以安全地忽略此操作


因为
FileChannel
也是可关闭的
FileChannel::close
也会关闭底层流。

RandomAccessFile f=new RandomAccessFile(新文件(“a.txt”),“rw”);try(FileChannel ff=f.getChannel();){}try{f.read();}catch(异常值){ex.printStackTrace();}