I'm writing a program that uses IOExceptions and I'm coming across an error that I can't figure out. The code is
Main:
public class IOJ { public static void main(String[] args) { findStuff calc = new findStuff(); calc.findSyl(); //^ Unreported exception IOException, must be caught or declared to be thrown calc.printRes(); } } and the actual files that's throwing
import java.io.FileReader; import java.io.FileWriter; import java.io.BufferedReader; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; public class findStuff { private double findSyl; //find Syl private double printRes; //print results public double NumSylG = 0; //number of syllables public double findSyl()throws IOException { BufferedReader inputStream = null; PrintWriter outputStream = null; try { String newLine = ""; outputStream.println(newLine); String[] tokens = newLine.split(" "); char temp; for (int i = 0; i < newLine.length(); i++) { temp = newLine.charAt( i ); if (Character.isLetter(temp) ) NumSylG++; } } catch (IOException e) { System.err.println("Caught IOException: " + e.getMessage()); } finally { if (inputStream != null) inputStream.close(); if (outputStream != null) outputStream.close(); } return findSyl; } public double printRes() { System.out.printf("The total number of Syl in Gettysburg is: %.1f \n", NumSylG); return printRes; } } The findStuff file compiles just fine. it's when I call it from main is when I get that error. I'm still getting used to catching and throwing things so can anyone give me some insight on what I am doing wrong? Note: I didn't put the file path for privacy reasons.
UpperCasein Java.