/* * This version of DummiesIO runs under older versions of * Java, such as Java 1.1.8 and the Macintosh MRJ. */ import java.io.*; public class DummiesIO { static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); //Open a BufferedReader: static public BufferedReader open(String string) { FileInputStream f; try { f = new FileInputStream (string); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(1); return null; } InputStreamReader inp = new InputStreamReader(f); BufferedReader b = new BufferedReader(inp); return b; } //Create a new PrintStream for output: static public PrintStream create(String string) { FileOutputStream f; try { f = new FileOutputStream(string); } catch (IOException e) { e.printStackTrace(); System.exit(1); return null; } PrintStream p = new PrintStream(f); return p; } static public int getInt() { return getInt(keyboard); } static public int getInt(BufferedReader reader) { try { return Integer.parseInt(reader.readLine()); } catch (Exception e) { System.out.println("Cannot read an int value."); e.printStackTrace(); return 0; } } static public double getDouble() { return getDouble(keyboard); } static public double getDouble(BufferedReader reader) { try { return (Double.valueOf(reader.readLine())).doubleValue(); } catch (Exception e) { System.out.println("Cannot read a double value."); e.printStackTrace(); return 0.0; } } static public char getChar() { return getChar(keyboard); } static public char getChar(BufferedReader reader) { try { return reader.readLine().charAt(0); } catch (Exception e) { System.out.println("Cannot read a char value."); e.printStackTrace(); return 0; } } static public boolean getBoolean() { return getBoolean(keyboard); } static public boolean getBoolean(BufferedReader reader) { try { return (Boolean.valueOf(reader.readLine())).booleanValue(); } catch (Exception e) { System.out.println("Cannot read a boolean value."); e.printStackTrace(); return false; } } static public String getString() { return getString(keyboard); } static public String getString(BufferedReader reader) { try { return reader.readLine(); } catch (Exception e) { System.out.println("Cannot read a String value."); e.printStackTrace(); return ""; } } static public byte getByte() { return getByte(keyboard); } static public byte getByte(BufferedReader reader) { try { return Byte.parseByte(reader.readLine()); } catch (Exception e) { System.out.println("Cannot read a byte value."); e.printStackTrace(); return (byte)0; } } static public short getShort() { return getShort(keyboard); } static public short getShort(BufferedReader reader) { try { return Short.parseShort(reader.readLine()); } catch (Exception e) { System.out.println("Cannot read a short value."); e.printStackTrace(); return (short)0; } } static public long getLong() { return getLong(keyboard); } static public long getLong(BufferedReader reader) { try { return Long.parseLong(reader.readLine()); } catch (Exception e) { System.out.println("Cannot read a long value."); e.printStackTrace(); return 0L; } } static public float getFloat() { return getFloat(keyboard); } static public float getFloat(BufferedReader reader) { try { return (Float.valueOf(reader.readLine())).floatValue(); } catch (Exception e) { System.out.println("Cannot read a float value."); e.printStackTrace(); return 0.0F; } } }