私はApache Commons 1.4.1ライブラリを使用して、".tar.gz"
ファイルを圧縮および解凍しています。Apache Commonsを使用してTARファイルをuntarする方法
最後のビットに問題があります。TarArchiveInputStream
をFileOutputStream
に変換しています。奇妙なことに
、それはこのラインで破壊だ:C:\ DocumentsとSettings \ Administratorのマイドキュメント\ \ JavaWorkspace \ BackupUtility \ untarし
FileOutputStream fout = new FileOutputStream(destPath);
destPath
は、の正規のパスとファイルです\テスト\ SUBDIR \ testinsub.txt
エラーが発生:
Exception in thread "main" java.io.IOException: The system cannot find the path specified
何ができるか考えてみませんか?それで、なぜその道を見つけることができないのですか?
私は以下の全体の方法を取り入れています(ほとんどがhereから持ち出されています)。
private void untar(File dest) throws IOException {
dest.mkdir();
TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
// tarIn is a TarArchiveInputStream
while (tarEntry != null) {// create a file with the same name as the tarEntry
File destPath = new File(dest.toString() + System.getProperty("file.separator") + tarEntry.getName());
System.out.println("working: " + destPath.getCanonicalPath());
if (tarEntry.isDirectory()) {
destPath.mkdirs();
} else {
destPath.createNewFile();
FileOutputStream fout = new FileOutputStream(destPath);
tarIn.read(new byte[(int) tarEntry.getSize()]);
fout.close();
}
tarEntry = tarIn.getNextTarEntry();
}
tarIn.close();
}
これを尋ねるのは恥ずかしいですが、私はあなたのコードサンプルを使ってみました。私が作業していた特定の 'gzip'ファイルがあれば動作していました。これは、inputStreamで読み込まれたコンテンツがある場合、 'fout.write(...) 'を呼び出すことなくどのように動作しますか? [answer @ user1894600 suggests](http://stackoverflow.com/a/14211580/320399)では、彼は明示的に 'write(...)'を呼び出して、メモリに読み込まれたバイト配列を提供しなければなりません。 – blong