java - FileUtils.listFiles() on resources directory -
in project have resources
directory my_directory
inside. my_directory
contains text files.
i want loop directory with:
url resource = resources.class.getresource("/my_directory"); file directory = new file(resource.getpath()); collection<file> files = fileutils.listfiles(directory, new string[]{"txt"}, true);
files
collection contains .txt
files.
it works if run project in debugger. if build project jar
file, gives error:
java.lang.illegalargumentexception: parameter 'directory' not directory
directory
file path is:
/home/hsz/.../lib/my_project.jar!/my_directory
how can utilize apache's fileutils
on resources directory ?
when files / directories bundled within .jar file, no longer treated file
objects. can read acquiring inputstream like
inputstream input = getclass().getresourceasstream("my_directory/file");
i suggest maintain folder files in filesystem , create operations want perform. there reason, want bundle them jar prior these manipulation.
as per reply in below question, in java 7, can create filesystem jar (zip) file, , utilize nio's directory walking , filtering mechanisms search through it. create easier write code handles jars , "exploded" directories. can seek that!
java resources apache-commons-io
No comments:
Post a Comment