Java resource as file

Posted by Martin Riedel on Stack Overflow See other posts from Stack Overflow or by Martin Riedel
Published on 2009-03-24T03:43:18Z Indexed on 2010/05/03 16:08 UTC
Read the original article Hit count: 375

Filed under:
|
|

Is there a way in Java to construct a File instance on a resource retrieved from a jar through the classloader?

My application uses some files from the jar (default) or from a filesystem directory specified at runtime (user input). I'm looking for a consistent way of
a) loading these files as a stream
b) listing the files in the user-defined directory or the directory in the jar respectively

Edit: Apparently, the ideal approach would be to stay away from java.io.File altogether. Is there a way to load a directory from the classpath and list its contents (files/entities contained in it)?

© Stack Overflow or respective owner

Related posts about java

Related posts about classloader