Results 1 to 4 of 4
  1. #1
    twiggy62's Avatar
    twiggy62 is offline Member
    Join Date
    Feb 2010
    Posts
    26
    Rep Power
    0

    Default Closing input streams

    If I declare:

    Java Code:
    FileInputStream fis = new FileInputStream(storedListFile);
    ObjectInputStream ois = new ObjectInputStream(fis);
    ois.close();
    Will that close both streams, or would I have to declare:

    Java Code:
    fis.close();
    ois.close();
    The biggest room in the world, is room for improvement.

  2. #2
    nigamsir is offline Member
    Join Date
    Mar 2010
    Posts
    11
    Rep Power
    0

    Default

    close both ....

  3. #3
    debylni is offline Member
    Join Date
    Mar 2010
    Location
    Bretejovce, Slovakia
    Posts
    4
    Rep Power
    0

    Lightbulb

    It will close both streams because fis is bound to ois so when you declare ois.close(); it will close both streams.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by twiggy62 View Post
    If I declare:

    Java Code:
    FileInputStream fis = new FileInputStream(storedListFile);
    ObjectInputStream ois = new ObjectInputStream(fis);
    ois.close();
    Will that close both streams, or would I have to declare:

    Java Code:
    fis.close();
    ois.close();
    The close() method is guaranteed to release any resource (like an open file); wrapper streams have to close the wrapped streams to do so. You only have to close the outermost stream.

    kind regards,

    Jos

Similar Threads

  1. Replies: 7
    Last Post: 02-24-2010, 08:00 PM
  2. Runtime.exec(), handling input and output streams
    By crookshank in forum New To Java
    Replies: 0
    Last Post: 06-05-2008, 02:41 PM
  3. Using Filtered Streams
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-12-2007, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •