Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Eclipse java 警告:资源泄漏:“未分配的可关闭值”永远不会关闭
try(FileChannel f = new RandomAccessFile(new File(p),"rw").getChannel();){}
泄漏点在哪里?
资源是 RandomAccesFile。你正在做一个新的对象,但你没有将它存储到任何变量中,所以你永远不能关闭它 randomAccesFile.close()。
您可以放心地忽略这一点。
由于FileChannelis alsoCloseable并且FileChannel::close还关闭了基础流。
FileChannel
Closeable
FileChannel::close