Skip to content

Instantly share code, notes, and snippets.

@sebglazebrook
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save sebglazebrook/9198979 to your computer and use it in GitHub Desktop.

Select an option

Save sebglazebrook/9198979 to your computer and use it in GitHub Desktop.
Read text file from a package
// Quite different to ruby. Took me a little longer to find out how to do it than it should.
def template(filename) {
def input = getClass().getResourceAsStream("/path/to/package/${filename}.template")
new InputStreamReader(input, 'utf-8')
}
// If file is in your 'resources' folder then use the below
def templateFromResources(filename){
def input = getClass().getResourceAsStream("templates/${filename}.template")
new InputStreamReader(input, 'utf-8')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment