"cannot find symbol" when trying to close I/O objects
exception, java
Solution
BufferedReader br = null;
FileInputStream fis =null;
DataInputStream dis null;
try {
fis = new FileInputStream(FileName);
dis = new DataInputStream(fis);
br = new BufferedReader(new InputStreamReader(dis));
}
Put them out of your `try block`, so that your finally block can see the variables.
Problem
``` public static int howMany(String FileName) { BufferedReader br = null; try { FileInputStream fis = new FileInputStream(FileName); DataInputStream dis = new DataInputStream(fis); br = new BufferedReader(new InputStreamReader(dis)); } catch (FileNotFoundException e) { System.out.print("FILE DOESN'T EXIST"); } finally { fis.close(); dis.close(); br.close(); } String input; int count = 0; try { while ((input = br.readLine()) != null) { count++; } } catch (IOException e) { System.out.print("I/O STREAM EXCEPTION"); } return count; } ``` For some reason, I cannot close any I/O objects. fis.close(), dis.close(), br.close() all give me cannot find symbol even though I imported all the I/O library (import java.io.*;) and initiated all the objects.