A parameterized constructor that accepts a filename as a String argument. Your constructor will open the file. If there is a problem opening the file, the constructor will throw the appropriate exception back to the calling routine.
Here is what i have so far, and i am wondering if this is the correct way to go about it?
public class WordCount
{
//creates BufferedReader to read/open the input file
private BufferedReader br=null;
//print writer to write to a file
private PrintWriter pw=null;
public WordCount(String afile) throws Exception
{
//if the file the user puts in does not exist, then throw an exception
try
{
br=new BufferedReader(new FileReader(afile));
}
catch(FileNotFoundException fnfe)
{
System.out.println(fnfe.getMessage());
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}

New Topic/Question
Reply




MultiQuote




|