code: import java.io.BufferedReader;
  import java.io.FileReader;
  import java.io.IOException;
  
  public class ReadFile {
      public static void main(String[] args) throws IOException{
          String fileContents = readEntireFile("./foo.txt");
      }
  
      private static String readEntireFile(String filename) throws IOException {
          FileReader in = new FileReader(filename);
          StringBuilder contents = new StringBuilder();
          char[] buffer = new char[4096];
          int read = 0;
          do {
              contents.append(buffer, 0, read);
              read = in.read(buffer);
          } while (read >= 0);
          in.close();
          return contents.toString();
      }
  }
  