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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:02:27+00:00 2026-06-09T05:02:27+00:00

I am wondering why I get this warning with the new eclipse Juno despite

  • 0

I am wondering why I get this warning with the new eclipse Juno despite I think I correctly closed everything. Could you please tell me why I get this warning in the following piece of code?

public static boolean copyFile(String fileSource, String fileDestination)
{
    try
    {
        // Create channel on the source (the line below generates a warning unassigned closeable value) 
        FileChannel srcChannel = new FileInputStream(fileSource).getChannel(); 

        // Create channel on the destination (the line below generates a warning unassigned closeable value)
        FileChannel dstChannel = new FileOutputStream(fileDestination).getChannel();

        // Copy file contents from source to destination
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());

        // Close the channels
        srcChannel.close();
        dstChannel.close();

        return true;
    }
    catch (IOException e)
    {
        return false;
    } 
 }
  • 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-09T05:02:30+00:00Added an answer on June 9, 2026 at 5:02 am

    IF you’re running on Java 7, you can use the new try-with-resources blocks like so, and your streams will be automatically closed:

    public static boolean copyFile(String fileSource, String fileDestination)
    {
        try(
          FileInputStream srcStream = new FileInputStream(fileSource); 
          FileOutputStream dstStream = new FileOutputStream(fileDestination) )
        {
            dstStream.getChannel().transferFrom(srcStream.getChannel(), 0, srcStream.getChannel().size());
            return true;
        }
        catch (IOException e)
        {
            return false;
        } 
    }
    

    You won’t need to explicitly close the underlying channels. However if you’re not using Java 7, you should write the code in a cumbersome old way, with finally blocks:

    public static boolean copyFile(String fileSource, String fileDestination)
    {
        FileInputStream srcStream=null;
        FileOutputStream dstStream=null;
        try {
          srcStream = new FileInputStream(fileSource); 
          dstStream = new FileOutputStream(fileDestination)
          dstStream.getChannel().transferFrom(srcStream.getChannel(), 0, srcStream.getChannel().size());
            return true;
        }
        catch (IOException e)
        {
            return false;
        } finally {
          try { srcStream.close(); } catch (Exception e) {}
          try { dstStream.close(); } catch (Exception e) {}
        }
    }
    

    See how much better the Java 7 version is 🙂

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

Sidebar

Related Questions

Wondering if I could get some advice and direction on this following requirement: Need
I was wondering how to get this to run. In my application I have
I was wondering how I would be able to get this working? I've read
I am wondering if its possible to get $(this).scrollTop() value after an anchor jump.
This is me showing that I didn't get a CS degree. What I'm wondering
This is what I got so far; <?php ReflectionFunction::export(new ReflectionFunction(filter_input())); And I get this
I get this warning saying that tmpnam is dangerous, but I would prefer to
Warning: I am brand new to NHibernate! I have a User object. This User
I get the following warning listed below and I was wondering how do I
I'm wondering if oci_connect() can cause a 1438 error, because i get this all

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.