关闭ZipFileSystem时发生java.nio.channels.ClosedChannel异常
我在关闭ZipFileSystem时随机出现以下错误:关闭ZipFileSystem时发生java.nio.channels.ClosedChannel异常,java,zip,nio,Java,Zip,Nio,我在关闭ZipFileSystem时随机出现以下错误: [16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: java.nio.channels.ClosedChannelException [16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at sun.nio.ch.F
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: java.nio.channels.ClosedChannelException
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at sun.nio.ch.FileChannelImpl.ensureOpen(FileChannelImpl.java:109)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at sun.nio.ch.FileChannelImpl.position(FileChannelImpl.java:275)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at sun.nio.ch.FileChannelImpl.position(FileChannelImpl.java:49)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.readFullyAt(ZipFileSystem.java:952)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.readFullyAt(ZipFileSystem.java:945)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.copyLOCEntry(ZipFileSystem.java:1155)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.sync(ZipFileSystem.java:1259)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.close(ZipFileSystem.java:277)
Map<String, String> env = new HashMap<>();
env.put("create", "true");
URI classCachesURI = classCachesZip.toURI();
URI classCachesZipURI = new URI("jar:" + classCachesURI.getScheme(), classCachesURI.getPath(), null);
cacheFileSystem = FileSystems.newFileSystem(classCachesZipURI, env, null);
这不是一个例外,而是一条从com.sun.nio.zipfs.ZipFileSystem:sync
多次打印的消息(每个文件一次)。我不知道发生了什么,以及ClosedChannelException
指的是哪个频道。发生这种情况时,文件不会保存到ZipFileSystem
以下是我创建ZipFileSystem的方法:
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: java.nio.channels.ClosedChannelException
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at sun.nio.ch.FileChannelImpl.ensureOpen(FileChannelImpl.java:109)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at sun.nio.ch.FileChannelImpl.position(FileChannelImpl.java:275)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at sun.nio.ch.FileChannelImpl.position(FileChannelImpl.java:49)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.readFullyAt(ZipFileSystem.java:952)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.readFullyAt(ZipFileSystem.java:945)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.copyLOCEntry(ZipFileSystem.java:1155)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.sync(ZipFileSystem.java:1259)
[16:59:27] [Thread-1/INFO] [STDERR]: [com.sun.nio.zipfs.ZipFileSystem:sync:1262]: at com.sun.nio.zipfs.ZipFileSystem.close(ZipFileSystem.java:277)
Map<String, String> env = new HashMap<>();
env.put("create", "true");
URI classCachesURI = classCachesZip.toURI();
URI classCachesZipURI = new URI("jar:" + classCachesURI.getScheme(), classCachesURI.getPath(), null);
cacheFileSystem = FileSystems.newFileSystem(classCachesZipURI, env, null);
并关闭它:
cacheFileSystem.close();
我看了很多次文档,看不出我可能做错了什么。我应该做些什么来避免这个问题?对我很有用。请提供一个。@SotiriosDelimanolis创建文件系统,用上面的代码向其中写入一些文件,然后关闭它会导致随机出现问题(大约1/10次)。