Java 如何使用TrueZip TPath复制文件?
作为如何使用TrueZip将一个压缩文件的内容复制到另一个压缩文件的后续步骤?当我调用:Java 如何使用TrueZip TPath复制文件?,java,truezip,Java,Truezip,作为如何使用TrueZip将一个压缩文件的内容复制到另一个压缩文件的后续步骤?当我调用: TPath sourceFile = new TPath("c:/foo.zip"); TPath targetFile = new TPath("c:/bar.jar"); Files.copy(sourceFile, targetFile, StandardCopyOption.COPY_ATTRIBUTES); 我得到: java.io.FileNotFoundException: C:\foo.z
TPath sourceFile = new TPath("c:/foo.zip");
TPath targetFile = new TPath("c:/bar.jar");
Files.copy(sourceFile, targetFile, StandardCopyOption.COPY_ATTRIBUTES);
我得到:
java.io.FileNotFoundException: C:\foo.zip (expected FILE - is DIRECTORY)
at de.schlichtherle.truezip.nio.file.TFileSystemProvider.copy(TFileSystemProvider.java:397)
at de.schlichtherle.truezip.nio.file.TFileSystemProvider.copy(TFileSystemProvider.java:364)
at java.nio.file.Files.copy(Files.java:1219)
事实上,我知道c:/foo.zip
是一个现有文件,而不是目录
回答我自己的问题。。。请注意,我通过反复试验得出了这一结论,因此我可能在以下几点上出错:
Files.walkFileTree(源文件,新的SimpleFileVisitor()
{
@凌驾
公共文件VisitResult visitFile(路径文件,基本文件属性属性属性)引发IOException
{
Files.copy(file,targetFile.resolve(sourceFile.relativize(file)),
标准复制选项。复制属性);
返回super.visitFile(文件,attrs);
}
});
三,。是的,您可以使用:targetFile.getFileSystem().sync(FsSyncOptions.UMOUNT)代码>
Files.walkFileTree(sourceFile, new SimpleFileVisitor<Path>()
{
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
Files.copy(file, targetFile.resolve(sourceFile.relativize(file)),
StandardCopyOption.COPY_ATTRIBUTES);
return super.visitFile(file, attrs);
}
});