2017-08-29 52 views
2

有沒有辦法打開AsynchronousFileChannel存儲在類路徑上的jar文件?AsynchronousFileChannel爲文件在罐子裏

如果我嘗試直接創建Path,則獲得FileSystemNotFoundException。 如果我創建文件系統第一:

URI uri = ...; //get the URI of a file in a jar 
String[] array = uri.toString().split("!"); 
FileSystem fs = FileSystems.newFileSystem(URI.create(array[0]), Collections.emptyMap()); 
Path path = fs.getPath(array[1]); 
AsynchronousFileChannel ch = AsynchronousFileChannel.open(path); 

它與UnsupportedOperationException :(

有什麼辦法來實現這一爆炸

我的項目是春季(以及使用ClassPathResource此),所以Spring的具體解決方案有效

回答

1

JDK中的zip文件系統提供者不支持異步I/O,所以這就是爲什麼UOE被拋出的原因