Why is it asking me to initialize the variable fin
FileInputStream fin;
File f = new File("C:/Users/NetBeansProjects/QuestionOne/input.txt");
fin = new FileInputStream(f);
When trying to close the file
fin.close();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I bet this is not exactly the same code that generated the compiler error. Almost sure you declared your variables outside the try-catch-finally block but you initialized them within the try block, which implies the variable may not be initialized in the context of the catch or finally blocks where the compiler error is occurring
For example:
If you are using JDK 7 perhaps the best way is to use the try with resources to deal with the closing of your stream: