问题
When I invoke:
File input = new File("cmake.tar.gz");
TFile sourceFile = new TFile(input);
TFile targetFile = new TFile(File.createTempFile("cmake", ".zip"));
try
{
TFile.cp_rp(sourceFile, targetFile, TArchiveDetector.NULL);
}
finally
{
TFile.umount(targetFile);
}
I get:
java.io.IOException: C:\Users\Gili\AppData\Local\Temp\cmake4527983120069708378.zip (not a directory)
at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:163)
at de.schlichtherle.truezip.file.TBIO.cp_r(TBIO.java:142)
at de.schlichtherle.truezip.file.TFile.cp_rp(TFile.java:3364)
at com.googlecode.cmakemavenproject.GetBinariesMojo.download(GetBinariesMojo.java:275)
How can I instruct TrueZip to create a new .zip file containing the contents of the .tar.gz file?
回答1:
The issue is that the target archive file already exists as an empty file once you've called File.createTempFile(*), which will be treated as a false positive archive file by the TrueZIP Kernel. According to this logic, your subsequent call to TFile.cp_rp(*) tries to recursively copy a virtual directory to a plain file, which cannot work.
To make your code work, simply call File.delete() on the object returned by File.createTempFile(*). The remainder of your code should then work.
回答2:
I've not used TrueZip, but a quick scan of the API docs leads me to conclude that you can't use TFile
in this way. A TFile
object represents a single member of an archive. If you want to copy all members you must iterate over the input members yourself and copy each one.
There may be an API to handle entire archives, but I didn't see it.
来源:https://stackoverflow.com/questions/9266974/convert-tar-gz-file-to-zip-using-truezip