Share this page 

Read a file into a variable in one shotTag(s): IO


import java.io.*;

public class ReadFullyIntoVar {
   public static void main(String argv[]){
     try {
       FileInputStream file = new FileInputStream (argv[0]);
       DataInputStream in = new DataInputStream (file);
       byte[] b = new byte[in.available ()];
       in.readFully (b);
       in.close ();
       String result = new String (b, 0, b.length, "Cp850");
       /* */
       System.out.println(result);
       }
     catch (Exception e) {
       e.printStackTrace();
       }
     }
}