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

  • Home
  • SEARCH
  • 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 7784455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:05:52+00:00 2026-06-01T20:05:52+00:00

I am trying to learn programming on my own time and I am still

  • 0

I am trying to learn programming on my own time and I am still trying to get the hang of it. I am getting the following error:

java.io.IOException: The handle is invalid

Here is my code

public class PrimeFinder {
private int[] prime;
FileInputStream input = null;
//default contructor uses the premade file prime.txt that has the first 10000 digits of pi
public PrimeFinder() throws IOException {
    try{
        input = new FileInputStream ("primes.txt");
    }
    finally {
        if (input != null ) {
            input.close();
        }
    }
}
//constructor with a predefined text file to use.
public PrimeFinder(String txtFile) throws IOException {
    try{
        input = new FileInputStream(txtFile);
    }
    finally {
        if (input != null ) {
            input.close();
        }
    }
}
public static void main(String[] args) throws IOException{

    PrimeFinder tester  = new PrimeFinder();
    tester.arrayListWithNumbers();
}
}

I believe I’m getting the error whenever I invoke the arrayListWithNumbers() method, when I attempt to show the number of bytes in the default constructor, then it works perfectly fine and shows a tally of 101281 bytes.

  • 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-01T20:05:53+00:00Added an answer on June 1, 2026 at 8:05 pm

    Well you’re closing input in the finally block of the constructor, before you actually start using it. Move the closing part out of the constructor to somewhere it will be called when you’re done, such as below the call to arrayListWithNumbers or a separate close method that you call from you main.

    I think you are confusing finally with finalize() which you should not use for this purpose either.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to learn some programming on my own by working through the
I'm trying to learn PHP programming through trial, error and lots and lots of
Greetings, I am currently trying to learn some Java programming. To do this I'm
trying to learn windows programming in java, want to display a image to a
I'm making my first Java project, and trying to learn OO programming as well
I am trying to learn java web programming. I come from a perl scripting
I am a Java newbie trying to learn network programming and concurrency, and I
I'm trying to learn some Android and java programming in Eclipse. I can run
I am trying to learn object oriented programming in the context of Java. I
I am trying to learn web programming in python. I am converting my old

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.