public static String readTextfile(final File file) throws IOException {
  final StringBuffer contents=new StringBuffer();
  final String lineSeparator=System.getProperty("line.separator");
  try (BufferedReader input=new BufferedReader(new FileReader(file))){
    String line=null;
    while ((line=input.readLine()) != null) {
      contents.append(line);
      contents.append(lineSeparator);
    }
  }
   return contents.toString();
}

public static String readTextfile ( final File file ) throws IOException { final StringBuffer contents = new StringBuffer ( ) ; final String lineSeparator = System . getProperty ( "line.separator" ) ; try ( BufferedReader input = new BufferedReader ( new FileReader ( file ) ) ) { String line = null ; while ( ( line = input . readLine ( ) ) != null ) { contents . append ( line ) ; contents . append ( lineSeparator ) ; } } return contents . toString ( ) ; }
reads a text file into a string .
