import java.io.*; import java.lang.*; public class WholeFileReader { public String readFile(String path) { try { File file = new File (path); FileReader fReader = new FileReader(file); BufferedReader in = new BufferedReader(fReader); String inputLine; StringBuffer strDocument = new StringBuffer(); while ((inputLine = in.readLine()) != null) { strDocument.append(inputLine+"\n"); //throw new IOException(); } System.out.println("Closing File!"); fReader.close(); return strDocument.toString(); } catch(FileNotFoundException ex) { System.out.println("The specified file was not found at "+ path); return ""; } catch(IOException ex) { System.out.println("IOException occured while reading from file "+path); } return "Nothing to return.."; } public static void main(String args[]) { WholeFileReader wfr = new WholeFileReader(); try { System.out.println(wfr.readFile(args[0]) ); } catch(IndexOutOfBoundsException ex) { System.out.println("No file has been specified from command line!\n"); } } }