I need to create a tar file which would have directories and files underneath. Example:
while(itr.hasNext()) {
String dir = itr.next();
File f = new File("/tmp/apps/"+dir);
f.getParentFile().mkdirs();
File contentFile = new File(f, "myfile.txt");
if(!contentFile.exists()) {
contentFile.createNewFile();
}
Writer out = new FileWriter(contentFile);
BufferedWriter bw = new BufferedWriter(out);
bw.write(someString);
bw.close();
}
//tar the content from /tmp/apps as apps.tar which sould have some directories
and files
There is nothing in the JDK itself that would be helpful for you. I would recommend you add a dependency on Apache Commons-Compress ( http://commons.apache.org/compress/ ).
See TarArchiveOutputStream and TarArchiveEntry in the documentation : http://commons.apache.org/compress/examples.html#tar
Does it help ?