here is my problem, so far I’ve compressed a file (.zip) and also in another application I can request to the system to display a file with the application that the system has as default to open “that” kind of file (.txt -> notepad, .doc(x) -> Word, .psd -> Photoshop, etc…) (Desktop.getDesktop().open(f);), the problem is, how can I request to the system to display a file that is inside the zip file without unzipping it?
for example using Winrar you can see the content of the zip, and if you double click over one of the files inside, the file is open with the preferred/default viewer/editor of the system, and the .zip file remains zipped (apparently, or at least you did not need to uncompressed the entire .zip to have access to the file you want) is it possible to do that with java? (and preferably only using java).
To be able to pass the file itself to another application you need to extract it somewhere, otherwise other applications can’t have access to it.
Actually this is how WinRAR does, in Java you can do it through
ZipFileandZipEntryand yes, you will have to extract it for sure.Java itself caches files in the folder specified by the property
"java.io.tmpdir"so I guess you could try to look for them when processing the zip entries so that they will be automatically deleted by the JVM upon termination without bothering yourself.To pipe a ZipInputStream to a file you can just use an utility function like this one (I personally used it to work with zip files so I tested it):
To be used as