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 8821091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:46:06+00:00 2026-06-14T05:46:06+00:00

Now I am getting compile time error at line 30 and 38 that ‘fin’

  • 0

Now I am getting compile time error at line 30 and 38 that ‘fin’ might not have been initialized. but its perfectly to write it this way

 import java.io.*;
    class CopyFile {
        public static void main(String args[]) throws IOException {
            int i;
            FileInputStream fin;//can't it be done like this?
            FileOutputStream fout= new FileOutputStream(args[1]);

            try{
                //open input file
                try{
                    fin = new FileInputStream(args[0]);
                }
                catch(FileNotFoundException e){
                    System.out.println("Input file Not Found");
                    return;
                }
                //open output file
                try{
                    fout = new FileOutputStream(args[1]);
                }
                catch(FileNotFoundException e){
                    System.out.println("Error Opening File");
                }
            }
            catch(ArrayIndexOutOfBoundsException e){
                System.out.println("usage: Copyfile From to");
            }
            try{
                do{
                    i = fin.read();
                    if(i!= -1)
                        fout.write(i);
                }while(i != -1);
            }
            catch(IOException e){
                System.out.println("file error");
            }
            fin.close();
            fout.close();
        }
    }

I have seen it many time initialized like this. I think its due to the try blocks.

it might miss the initialization due to being in the try block and hence the error?

  • 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-14T05:46:07+00:00Added an answer on June 14, 2026 at 5:46 am

    The problem is that you’re not initializing the FileInputStream fin at all. Your code will look like this to the compiler:

    FileInputStream fin;
    try {
        fin = ...
        //more code goes here...
    } catch (...) {
        //exception handling...
    } finally {
        fin.close(); //fin is not even null for the compiler
    }
    

    In order to make the code work, initialize it at least with a null value and check if fin != null before using the close method.

    FileInputStream fin = null;
    try {
        fin = ...
        //more code goes here...
    } catch (...) {
        //exception handling...
    } finally {
        if (fin != null) {
            fin.close(); //fin is not null, at least the JVM could close it
        }
    }
    

    More info:

    • Java: Declaring Variables
    • Uninitialized variables and members in Java
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been getting this error for quite some time now and Google has
I have been developing a library that is getting pretty large, and now I
Now getting error Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT
I had a class loader working although I am now getting an error after
I just upgraded jQuery to version 1.4.2 and I am now getting an error
Up until now I used DateTime.Now for getting timestamps, but I noticed that if
I'm trying to compile some code. Here is the error I'm getting: error while
I should get this by now, but I'm just not getting it yet. The
So I keep getting this error when trying to compile C++ code using CodeBlocks.
I'm getting an error when I try to compile or run the application. Performing

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.