是否可以在java中使用Truezip提取大文件?

时间:2011-12-13 02:39:21

标签: truezip

import java.io.IOException;
import utils.myDate;
import utils.myLog;
import de.schlichtherle.truezip.file.TArchiveDetector;
import de.schlichtherle.truezip.file.TFile;

public class Main 
{
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    Extract(new String("C:/Documents and Settings/mitracomm/My Documents/Downloads/JAR"), new String("D:/Source/Extract Result") , "");     
}

private static void Extract(String src, String dst, String incPath)
{
    TFile srcFile = new TFile(src + "/" + incPath);
    TFile dstFile = new TFile(dst);

    try {
        TFile.cp_rp(srcFile, dstFile, TArchiveDetector.ALL);
    } catch (IOException e) {
        myLog.add(myDate.today("yyyyMMdd") + ".log", "error", e.getMessage());
    }
}

以上代码是否适用于大型存档?另外,如何在不必填写incPath或指定存档名称的情况下提取目录中的每个存档?我试图这样做,但我最终得到了源目录中所有档案的副本,而不是提取文件。

1 个答案:

答案 0 :(得分:4)

代码原则上没问题,但我会使用:

public class Main {
    public static void main(String[] args) {
        Extract(new String("C:/Documents and Settings/mitracomm/My Documents/Downloads/JAR"), new String("D:/Source/Extract Result") , "");        
    }

    private static void Extract(String src, String dst, String incPath) {
        TFile srcFile = new TFile(src, incPath);
        TFile dstFile = new TFile(dst);
        try {
            TFile.cp_rp(srcFile, dstFile, TArchiveDetector.NULL);
        } catch (IOException e) {
            // I don't like logging for this purpose, but if you must...
            myLog.add(myDate.today("yyyyMMdd") + ".log", "error", e.getMessage());
        }
    }
}

我不确定你是否真的想要Extract方法的三个参数。

最后,是的,TrueZIP正确处理超过4GB大小的ZIP文件。