Converting an InputStream to a String

Main.java:

import java.io.*;
 
public class Main
{
   public static void main(String []args) throws IOException {
      if (args.length != 1) {
         System.out.println("Usage: java Main <file>");
         System.exit(1);
      }
      
      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(args[0]));
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      
      long start = System.currentTimeMillis();
      int b;
      
      byte[] buf = new byte[2048];
      while ((b = bis.read(buf)) != -1) {
         baos.write(buf);
      }
      System.out.println("Time to read in file: " + (System.currentTimeMillis() - start));
      
      byte[] buffer = baos.toByteArray();
      
      String result = new String(buffer);  // or "new String(buffer, encoding)"

      System.out.println(result);
   }
}