如何使用java提取tgz文件

时间:2015-07-08 10:50:31

标签: java

是否有提取'tgz'文件的java代码。 我搜索了很多,但没有得到任何。所以我首先将其转换为tar文件,然后我使用代码提取tar文件。 但我的tar文件包含xml,sh和tgz文件,所以它被卡住了。 代码是:

public class test1 {


 public static void main(String[] args) throws Exception{
  File file = new File("D:\\Delta\\Interactive\\qml_windows\\development\\onemedia\\");

     final List<File> untaredFiles = new LinkedList<File>();
        final InputStream is = new FileInputStream("D:\\onemedia\\onemedia-dal-504-v4.tar"); 
        final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
        TarArchiveEntry entry = null; 
        while ((entry = (TarArchiveEntry)debInputStream.getNextEntry()) != null) {
            final File outputFile = new File(file, entry.getName());
            if (entry.isDirectory()) {
                if (!outputFile.exists()) {
                    if (!outputFile.mkdirs()) {
                        throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
                    }
                }
            } else {
                final OutputStream outputFileStream = new FileOutputStream(outputFile); 
                IOUtils.copy(debInputStream, outputFileStream);
                outputFileStream.close();
            }
            untaredFiles.add(outputFile);
        }
        debInputStream.close(); 


 }

}

此代码提取tar文件。 我仍然得到错误:

Exception in thread "main" java.io.FileNotFoundException: D:\onemedia\onemedia_4\adload.tgz (The system cannot find the path specified)

0 个答案:

没有答案