commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting (JIRA)" <>
Subject [jira] Commented: (IO-46) [io] Find file in classpath
Date Sat, 14 Feb 2009 15:05:59 GMT


Jukka Zitting commented on IO-46:

For example to place some input files on the test class path to fetch from when invoking File-based

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

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:
>             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.

View raw message