/** * After this method is called, input will be read from inputStream, provided it is non-null. If * inputStream is null, then this method has the same effect as calling readStandardInput(); that * is, future input will come from the standard input stream. */ public static void readStream(Reader inputStream) { if (inputStream == null) readStandardInput(); else { if (inputStream instanceof BufferedReader) in = (BufferedReader) inputStream; else in = new BufferedReader(inputStream); inputFileName = null; readingStandardInput = false; inputErrorCount = 0; } }
/** * Opens a file with a specified name for input. If the file name is null, this has the same * effect as calling readStandardInput(); that is, input will be read from standard input. If an * error occurs while trying to open the file, an exception of type IllegalArgumentException is * thrown, and the input source is not changed. If the file is opened successfully, then after * this method is called, all of the input routines will read from the file, instead of from * standard input. */ public static void readFile(String fileName) { if (fileName == null) // Go back to reading standard input readStandardInput(); else { BufferedReader newin; try { newin = new BufferedReader(new FileReader(fileName)); } catch (Exception e) { throw new IllegalArgumentException( "Can't open file \"" + fileName + "\" for input.\n" + "(Error :" + e + ")"); } if (!readingStandardInput) { // close current input stream try { in.close(); } catch (Exception e) { } } in = newin; readingStandardInput = false; inputErrorCount = 0; inputFileName = fileName; } }
/** * After this method is called, input will be read from inputStream, provided it is non-null. If * inputStream is null, then this method has the same effect as calling readStandardInput(); that * is, future input will come from the standard input stream. */ public static void readStream(InputStream inputStream) { if (inputStream == null) readStandardInput(); else readStream(new InputStreamReader(inputStream)); }