Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8771515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:48:28+00:00 2026-06-13T17:48:28+00:00

Why is it asking me to initialize the variable fin FileInputStream fin; File f

  • 0

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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:48:30+00:00Added an answer on June 13, 2026 at 5:48 pm

    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:

    FileInputStream fin;
    try {
       File f = new File("C:/Users/NetBeansProjects/QuestionOne/input.txt");
       fin = new FileInputStream(f);
    } finally {
       //you cannot be sure fin is initialized
       fin.close(); //compiler error
    }
    

    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:

    File f = new File("C:/Users/NetBeansProjects/QuestionOne/input.txt");
    try(FileInputStream fin=new FileInputStream(f)) {
        //some input stream handlung here
    }catch(IOException e){...} 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before asking the question let me preface with the fact that I am new
Firstly, I'm not asking how to perform a multi-file upload using CodeIgniter, but rather
I'm trying to track every class variable's history by metaprogramming. I'm not a fan
I'm asking some specific questions. How can I initialize them in a class? How
Is it possible to initialize Java system properties using some sort of configuration file?
Asking for your help on this Oracle query. It's giving me the error 2
Before asking my question, let me explain the context. CONTEXT: I have a web
Before asking a question, and before you all get mad because there are a
After asking my first question Windows Phone 7.1 app accessing Azure Storage directly ,
In asking around and doing some research, it seems like many people are really

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.