Results 1 to 4 of 4
  1. #1
    sonhmms is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default FileWriter is not closed on exit

    FileWriter sby_f = new FileWriter( f);
    BufferedWriter sby_writer = new BufferedWriter(sby_f);
    sby_writer.write("abc");
    sby_writer.write("\n");
    sby_writer.write("xyz");
    sby_writer.close();

    In this above code, FileWriter sby_f is not closed explicitly by code. I wanted to know if this is closed by sby_writer.close(); or it is still open. Please do reply.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You only need to close the outside wrapper object, the BufferedWriter. The tutorials will tell you this, and I recommend you have a look at them.

  3. #3
    sonhmms is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default

    So you say that, the fileWriter is not closed in tat code..rite?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by sonhmms View Post
    So you say that, the fileWriter is not closed in tat code..rite?
    No, Fubarable said the opposite: if you close the wrapper the wrapped stream is closed by the wrapper. You could've read this all in the API documentation.

    kind regards,

    Jos

Similar Threads

  1. issue with FileReader and FileWriter
    By Uma R in forum Advanced Java
    Replies: 6
    Last Post: 07-16-2010, 01:16 PM
  2. Replies: 1
    Last Post: 01-31-2010, 03:17 AM
  3. FileWriter doesn't write
    By superman5 in forum NetBeans
    Replies: 2
    Last Post: 07-30-2009, 05:46 AM
  4. JAva Filewriter
    By tommyyyy in forum New To Java
    Replies: 1
    Last Post: 03-28-2009, 12:51 PM
  5. scanner vs. BufferedReader? printstream vs. FileWriter?
    By diggitydoggz in forum New To Java
    Replies: 1
    Last Post: 01-09-2009, 01:58 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
  •