public static String readFileContents(File file) throws IOException {
  BufferedReader br=new BufferedReader(new FileReader(file));
  StringBuilder sb=new StringBuilder((int)file.length());
  try {
    char[] buf=new char[4096];
    int read;
    while ((read=br.read(buf)) != -1) {
      sb.append(buf,0,read);
    }
  }
  finally {
    br.close();
  }
  return sb.toString();
}

public static String readFileContents ( File file ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( file ) ) ; StringBuilder sb = new StringBuilder ( ( int ) file . length ( ) ) ; try { char [ ] buf = new char [ 4096 ] ; int read ; while ( ( read = br . read ( buf ) ) != - 1 ) { sb . append ( buf , 0 , read ) ; } } finally { br . close ( ) ; } return sb . toString ( ) ; }
reads the contents of a file .
