Created
June 18, 2013 13:34
-
-
Save YA2O/5805392 to your computer and use it in GitHub Desktop.
Read file as String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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