我有一个JSP应用程序,允许用户上传ZIP文件,然后应用程序将读取ZIP中的所有文件并将它们存储在MySQL中。
根据建议,我决定使用“Zip文件系统提供程序”来处理ZIP文件:
Path zipPath = Paths.get(zipFile.getSubmittedFileName());//returns the path to the ZIP file
FileSystem fs = FileSystems.newFileSystem(zipPath, null);//creates the file system
我尝试使用以下方法来遍历它:
for (FileStore store: fs.getFileStores()) {
System.err.println("Store: " + store.name());
}
然而,它仅循环一次并返回整个ZIP文件
tmp.zip
。 我如何逐个提取物理图像文件,以便可以将它们存储在MySQL中?
for (Path rootDir : fs.getRootDirectories)
- JesperFiles.walk
- 这只需要一行代码。您正在遍历底层的存储(即zip),而您需要查看文件系统。例如,可以使用fs.getPath("/")
。 - Boris the Spidernull
?fs.getRootDirectories()
会返回null
吗?那将非常奇怪。 - JesperFileSystem.getRootDirectories()
不能返回null
。 - Boris the Spider