tags:

views:

51

answers:

3

I have some files inside a jar which I would like to access in Java using a File object rather than as a stream. Is it possible to do this?

+2  A: 

Look at JarFile.

mcandre
He said "using a File object rather than as a stream". I don't particularly understand why, but your solution gives him the stream he didn't want.
Alan Krueger
+1  A: 

java.io.File is an abstraction from os specific handling of files. If you use java.io.File in your code, the code should run on all Java platforms.

The Jar is not a os file system. So it makes no sense to apply java.io.Files from the Java core classes.

I don't want to say it is not possible. Maybe it has sense for certain application and there is a library for that kind of abstraction.

PeterMmm
A .jar file is a .zip file so I would try looking for ZIP libraries that provide a File abstraction. (After I gave up advocating for the Stream route.)
Chris Nava
A: 

You can also access it as a URL with a "jar:" prefix, but that's not a File object either, so I guess that doesn't meet the restriction.

Why do you have to access it as a File? This seems like asking, "Is there any way I can add two numbers without using the plus operator?" Maybe you can, but why do you not want to do it the easy way?

Jay