Question: How would I create an object of MyFileReader (MyFileReader.Java) in Program.Java to process txt files instead of what I have now, that for some reason

How would I create an object of MyFileReader (MyFileReader.Java) in Program.Java to process txt files instead of what I have now, that for some reason gives me IOExceptions and wont let me use it.

import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException;

public class MyFileReader { private String buffer = null; private BufferedReader in = null; public MyFileReader(String fileName) { try { in = new BufferedReader(new FileReader(fileName)); buffer = in.readLine(); // Store first line } catch (IOException e) { System.out.println("Cannot read file \'"+fileName+"\'"); System.exit(0); } } public boolean endOfFile() { if (buffer == null) return true; else return false; } public String readString() { String line = buffer; if (buffer == null) { System.out.println("Error. The end of file was reached, so another string cannot be read from it"); return null; } try { buffer = in.readLine(); } catch (IOException e) { System.out.println("Error. Cannot read from file"); System.exit(0); } return line; } public int readInt() { String line = readString(); if (line == null) return -1; else return Integer.parseInt(line); } public double readDouble() { String line = readString(); if (line == null) return -1.0; else return Double.parseDouble(line); } }

import java.io.*;

public class Program {

private int cityCount; private City cityArray[]; private CompressedArray array;

private String buffer = null; private BufferedReader in = null; public Program(String fileName, boolean showMap) { try { in = new BufferedReader(new FileReader(fileName)); buffer = in.readLine(); // Store first line } catch (IOException e) { System.out.println("Cannot read file \'"+fileName+"\'"); System.exit(0); } } public boolean endOfFile() { if (buffer == null) return true; else return false; } public String readString() { String line = buffer; if (buffer == null) { System.out.println("Error. The end of file was reached, so another string cannot be read from it"); return null; } try { buffer = in.readLine(); } catch (IOException e) { System.out.println("Error. Cannot read from file"); System.exit(0); } return line; } public int readInt() { String line = readString(); if (line == null) return -1; else return Integer.parseInt(line); } public double readDouble() { String line = readString(); if (line == null) return -1.0; else return Double.parseDouble(line); }

public City[] getCityArray() { return cityArray; } public void expandCapacity() { City temp[]=cityArray; City cityArray[]=new City[temp.length+3]; for(int i=0;i

for(int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!