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;
}

}

No comments:

Post a Comment