[
https://issues.apache.org/jira/browse/IO-46?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12673515#action_12673515
]
Jukka Zitting commented on IO-46:
---------------------------------
{quote}
For example to place some input files on the test class path to fetch from when
invoking File-based APIs.
{quote}
That seems a bit fragile, as the resources could also be contained in a jar
file included in the classpath. The only case I can see when this is not a
potential issue is when the application is in control of the classpath, in
which case it could just as well access the files directly instead of going
through the class loader.
I'm also not so eager to introduce methods that make it easier to modify
resources on the classpath...
Perhaps a better alternative would be a method that takes a classpath resource
and returns a temporary file that contains the same data. This would (at some
performance cost) satisfy the requirements of File-based APIs without worrying
about the complexities of class loading.
> [io] Find file in classpath
> ---------------------------
>
> Key: IO-46
> URL: https://issues.apache.org/jira/browse/IO-46
> Project: Commons IO
> Issue Type: Improvement
> Components: Utilities
> Affects Versions: 1.1
> Environment: Operating System: other
> Platform: Other
> Reporter: David Leal
> Priority: Minor
> Fix For: 2.x
>
>
> Just to suggest adding a method like this:
> public File findFileInClasspath(String fileName) throws
> FileNotFoundException
> {
> URL url = getClass().getClassLoader().getResource(fileName);
> if (url == null){
> throw new FileNotFoundException(fileName);
> }
> return new File(url.getFile());
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.