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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:57:58+00:00 2026-05-10T15:57:58+00:00

Alright, I have been doing the following (variable names have been changed): FileInputStream fis

  • 0

Alright, I have been doing the following (variable names have been changed):

 FileInputStream fis = null; try {     fis = new FileInputStream(file);      ... process ...  } catch (IOException e) {     ... handle error ... } finally {     if (fis != null)         fis.close(); }  

Recently, I started using FindBugs, which suggests that I am not properly closing streams. I decide to see if there’s anything that can be done with a finally{} block, and then I see, oh yeah, close() can throw IOException. What are people supposed to do here? The Java libraries throw too many checked exceptions.

  • 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. 2026-05-10T15:57:59+00:00Added an answer on May 10, 2026 at 3:57 pm

    For Java 7 and above try-with-resources should be used:

    try (InputStream in = new FileInputStream(file)) {   // TODO: work } catch (IOException e) {   // TODO: handle error } 

    If you’re stuck on Java 6 or below…

    This pattern avoids mucking around with null:

        try {         InputStream in = new FileInputStream(file);         try {             // TODO: work         } finally {             in.close();         }     } catch (IOException e) {         // TODO: error handling     } 

    For a more detail on how to effectively deal with close, read this blog post: Java: how not to make a mess of stream handling. It has more sample code, more depth and covers the pitfalls of wrapping close in a catch block.

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

Sidebar

Related Questions

Alright have been working to switch to jQuery 1.7's new and improved .on() function
Alright I want to create a .csv file in C#. I have been looking
Alright so I have been looking around (on SO and Google) to see if
Alright so I have been trying to get all of my separate classes (At
Alright as I have been asking the last couple days and inching closer and
Alright so I have no idea how to even begin doing this But basically
Alright so I have a task, that I have to let the client try
Alright, here's a quick explanation of what I am doing: I have a website
Alright, so I have been wondering how to do this for a while. Basically,
Alright, I know questions like this have probably been asked dozens of times, but

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.