2012-11-02 47 views
2

的Eclipse的Java警告:资源泄漏:'未分配的可关闭的价值”永远不会关闭日食Java资源泄漏

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

在哪里泄漏?

回答

1

资源是RandomAccesFile。你正在做一个新的这个对象,但是你不把它存储到任何变量中,所以你永远不能关闭它randomAccesFile.close()。

+0

RandomAccessFile f = new RandomAccessFile(new File(“a.txt”),“rw”); \t \t尝试(FileChannel FF = f.getChannel();) \t \t {} \t \t尝试{f.read();}赶上(例外){ex.printStackTrace();} –

1

您可以放心地忽略这一点。

由于FileChannel也是CloseableFileChannel::close也在基础流上关闭。