tar解凍してファイル読み取りする方法
メモっす。
ant.jarをApacheAntプロジェクトからダウンロード。
import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import org.apache.tools.tar.TarEntry; import org.apache.tools.tar.TarInputStream; public class UncompressTar { /** * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub FileInputStream fis = new FileInputStream(new File("C:\\tmp\\files.tar")); TarInputStream tin = new TarInputStream(fis); TarEntry tarEnt = tin.getNextEntry(); while (tarEnt != null) { //名前を取得 String name = tarEnt.getName(); System.out.println(name); //サイズを取得 int size = (int)tarEnt.getSize(); ByteArrayOutputStream bos = new ByteArrayOutputStream(size); tin.copyEntryContents(bos); byte[] data = bos.toByteArray(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); InputStreamReader isr = new InputStreamReader(dis); BufferedReader br = new BufferedReader(isr); System.out.println(br.readLine()); isr.close(); dis.close(); tarEnt = tin.getNextEntry(); } tin.close(); } }