×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Massimo Zappino
Added: Mar 4, 2015 9:31 AM
Modified: Aug 27, 2017 3:32 PM
Views: 33
  1. package support;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7.  
  8.  
  9. public class TextResourceReader {
  10.  
  11.     public String readFile(String filename) throws IOException {
  12.         InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
  13.         BufferedReader br = new BufferedReader(new InputStreamReader(is));
  14.         String s, file = "";
  15.         while ((s = br.readLine()) != null) {
  16.             file += s + "\n";
  17.         }
  18.  
  19.         return file;
  20.     }
  21. }
  22.