package io; /* MyReader.java A file reading utility. Basically a wrapper for the BufferedReader class, with the addition of a FileDialog to open files. Author: JRL 8/00 */ import java.io.*; import java.awt.*; public class MyReader { BufferedReader br; public MyReader() { openIt(getFileName()); } public MyReader(String filename) { openIt(filename); } void openIt (String filename) { try { br = new BufferedReader(new FileReader(filename)); } catch (Exception e) {System.out.println("MyReader -- open failed!" + e);} } public String giveMeTheNextLine() { try { return br.readLine(); } catch (Exception e) {System.out.println("MyReader -- read failed!" + e);} return ""; } public boolean hasMoreData() { try { return br.ready(); } catch (Exception e) {System.out.println("MyReader -- bad!" + e);} return false; } public void close() { try { br.close(); } catch (Exception e) {System.out.println("MyReader -- disaster!" + e);} } String getFileName() { FileDialog fd = new FileDialog(new Frame(), "Select Input File"); fd.setFile("input"); fd.show(); return fd.getDirectory()+fd.getFile(); // return the complete path } } // MyReader class