import java.io.*; class hiThere{ public static void main (String [] args) throws Exception { InputStreamReader isr = new InputStreamReader(System.in); FileReader fr = new FileReader("ouchy.txt"); //BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(fr); FileOutputStream fos = new FileOutputStream("amazing.txt"); PrintWriter screenPw = new PrintWriter(System.out, true); PrintWriter pw = new PrintWriter(fos, true); //screenPw.println("Please enter a number"); screenPw.println("..... reading lines from the file ....."); String inputty = "something"; int number = 42, n, count = 0; inputty = br.readLine(); while(inputty != null) { try { number = Integer.parseInt(inputty); count = count + 1; } catch (NumberFormatException nfe) { pw.println(nfe.getLocalizedMessage()); pw.println("oops -- that (ie \""+inputty+"\") was a weird integer??! Bye bye"); //System.exit(1); } n = number * 2 ; pw.println("Doubling " + number + " gives " + n); inputty = br.readLine(); //Thread.sleep(1000); } // end while loop screenPw.println("All done -- bye for now! (I did " + count + " calculations"); } }