Windows – I am trying to create a new Tar file with with the JTar lib with the following inside…
MyTarFile.tar--|
|--MyFolder--|
|--MyFile.zip
I can create it with the folder and the zip file right in the root of MyTarFile but I don’t know (and I looked around) how to create that folder AND have the zip file inside. I need to know what to use (the File object(s)) for the TarEntry(s) (is it one for folder and one for file…or one for both?) and what the InputStream should look like (I believe just a single one for the zip file but not sure). I am trying to create a file to mimic an existing format so I don’t have the option of just losing that folder as the software that uses the file will be looking for it. I can add the zip file to the MyFolder folder on the actual file system (again, this is on Windows) before tarring or not…whatever works is fine.
I have tried full paths and relative paths (seems the InputStream MUST have a full path though) with no luck. Running out of ideas other than switching libraries (perhaps JTar doesn’t support this).
Thanks!
Without seeing what you have already written, here is my best attempt at answering. I am unfamiliar with JTar, but after taking a look at the example on their main page, I wrote a quick test program that created a tar with one file in the root of the tar and one file in a directory in the tar, which I believe is what you are attempting to do. The code of interest to you is this:
Note that the second tar entry,
otherTarEntryis instantiated with a relative path as theentryNameargument in theTarEntryconstructor. This is a poorly named argument, as it is technically the path of the file in the tar, not just the name.With your example file names above, your code might look something like this: