« Return to Thread: Load static classpath resources

Re: Load static classpath resources

by Burt Beckwith :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
If it's in the same package as your class, then it'd be


String contents = getClass().getResourceAsStream('MyFile.txt').text


Burt


On Thursday 02 July 2009 10:26:33 pm Stan Carney wrote:
> Has anybody loaded files off the classpath in Grails before?
>
> In Java I'm used to doing something like this:
>
> file: com/blah/MyFile.txt
>
> package com.blah
>
> public class MyClass(){
>
> public void someting(){
> URL url = MyClass.class.getResource("/com/blah/MyFile.txt")
> }
> }
>
>
> Similar code in grails always returns null. I have tried
> getResourceAsStream, copying the file to the root of the project, etc...
> They all still return null.
>
> Thoughts?
>
> Stan




signature.asc (204 bytes) Download Attachment

 « Return to Thread: Load static classpath resources