Showing posts with label Read from file. Show all posts
Showing posts with label Read from file. Show all posts

Sunday, October 25, 2015

// Java read from a file and return the string
public static String readFile(String fileName){

try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {

String content = "";

String line = null;
   while ((line = reader.readLine()) != null) {
       content = content + line;
   }
   reader.close();
 
   return content;
 
} catch (IOException x) {
   System.err.format("IOException: %s%n", x);
   return null;
}

}