import java.util.*; import java.*; import java.io.*; //This class is responsible for basic file operations //The functions include public class FileReader{ public char sym; //The current character on the input, 0x00 = error, 0xff = EOF private BufferedReader in; private File f; private String lineString; private boolean errorCondition = false; public FileReader(String fileName) //Constructor: Opens a file and reads the first character into 'sym' { char temp; try { f = new File(fileName); in = new BufferedReader(new InputStreamReader(new FileInputStream(f))); Next(); } catch(FileNotFoundException fnfe) { System.out.println("Can not find File:" + fileName); } catch (IOException ioe) { System.out.println("Can not preform IO operation correctly:" + ioe); } }//End of the constructor /////////////////////////// public void Next() { int temp; if (errorCondition) { sym = 0; return; } try { temp = in.read(); if(temp == -1) //EndOfFile has been reached { sym = 255; return; } if ((temp == '\t') || (temp == '\n') || (temp == '\r')) //Because I don't want to handle tab or new line cases whenever I want to do file operations { sym = ' '; return; } else { sym = (char)temp; return; } }catch(IOException ioe) { System.out.println("Got stuck in in.read method" + ioe); } return; }//end of method Next /////////////////////////////////////////////////////////// public void Error(String ErrorMsg)//Signal an Error with current file position { errorCondition = true; System.out.println("An error has occured"); return; } }//End of class