Skip to content

Instantly share code, notes, and snippets.

@YA2O
Created June 18, 2013 13:34
Show Gist options
  • Save YA2O/5805392 to your computer and use it in GitHub Desktop.
Save YA2O/5805392 to your computer and use it in GitHub Desktop.
Read file as String
import org.apache.commons.io.FileUtils;
...
File file = new File(this.getClass().getClassLoader()
.getResource("/relativePath/fileName").toURI());
String st = FileUtils.readFileToString(file, "UTF-8");
if resource in same package as present file:
File file = new File(this.getClass().getClassLoader()
.getResource(MyClass.class.getPackage().getName()
.replace('.', '/') + '/' + "filename.extension").toURI());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment