public String readFileContent(File file){
  StringBuilder fileContentBuilder=new StringBuilder();
  if (file.exists()) {
    String stringLine;
    try {
      FileReader fileReader=new FileReader(file);
      BufferedReader bufferedReader=new BufferedReader(fileReader);
      while ((stringLine=bufferedReader.readLine()) != null) {
        fileContentBuilder.append(stringLine + "\n");
      }
      bufferedReader.close();
      fileReader.close();
    }
 catch (    FileNotFoundException e) {
      e.printStackTrace();
    }
catch (    IOException e) {
      e.printStackTrace();
    }
  }
  return fileContentBuilder.toString();
}

public String readFileContent ( File file ) { StringBuilder fileContentBuilder = new StringBuilder ( ) ; if ( file . exists ( ) ) { String stringLine ; try { FileReader fileReader = new FileReader ( file ) ; BufferedReader bufferedReader = new BufferedReader ( fileReader ) ; while ( ( stringLine = bufferedReader . readLine ( ) ) != null ) { fileContentBuilder . append ( stringLine + "\n" ) ; } bufferedReader . close ( ) ; fileReader . close ( ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return fileContentBuilder . toString ( ) ; }
reads a content from a file . this is an i / o operation and this method executes in the main thread , so it is recommended to perform the operation using another thread .
