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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:51:55+00:00 2026-06-06T00:51:55+00:00

I just opened some old code in the current Eclipe Juno Release Candidate and

  • 0

I just opened some old code in the current Eclipe Juno Release Candidate and noticed a shiny new warning: Resource leak. It was triggered by code like this:

FileChannel out = new FileOutputStream(file).getChannel();
try
{
    ...Do something with out...
}
finally
{
    out.close();
}

Eclipse thinks that the created file output stream is a resource leak. Actually I’m not sure if this is a false warning (And the close method of the FileChannel doesn’t close the stream, too) or if this is really a resource leak. I changed the code to this:

FileOutputStream outStream = new FileOutputStream(file);
try
{
    FileChannel out = outStream.getChannel();
    ...Do something with out...
}
finally
{
    outStream.close();
}

The warning is gone now but now I’m not sure if the close method of the FileChannel must be called. So maybe it must look like this:

FileOutputStream outStream = new FileOutputStream(file);
try
{
    FileChannel out = outStream.getChannel();
    try
    {
        ...Do something with out...
    }
    finally
    {
        out.close();
    }
}
finally
{
    outStream.close();
}

If using a file input channel and a file output channel then this results in four nested try…finally blocks and it all gets kind of bloated.

What do you think? Is it really necessary to close the channel AND the stream? Or is closing the stream enough?

  • 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-06T00:51:57+00:00Added an answer on June 6, 2026 at 12:51 am

    Ah, found the answer in the documentation of the close() method of FileOutputStream:

    If this stream has an associated channel then the channel is closed as well.
    

    So closing the stream is enough.

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

Sidebar

Related Questions

I just opened a file in IDA Pro and I found some code that
today I just opened my 1,5 month old project and wanted to add a
I just checked out a revision from Subversion to a new folder. Opened the
I just installed the latest version of F#, and opened an old solution to
Suppose you have just opened Chrome. There is a New Tab already open. My
just think that when I opened my file then when I want to write
I just downloaded the Orchard CMS , opened it up in VS2008 and hit
How can I detect if the user has just downloaded the application and opened
I have this huge VB project which i just got from some one. i
I'm inserting some data into a div container via ajax. When its just straight

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.