Results 1 to 3 of 3
  1. #1
    SCS17 is offline Member
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0

    Question FileOutputStream question...

    hello all,

    I have a question regarding Files and Streams. What happens if you dont close the stream that you are using with the close().. ??!
    I know that the OS allows a limited number of files to be opened at a time depending on your RAM and all of that stuff, but I mean on the short term,, what are the consequences ???
    I read that the file gets locked and you cant open it or delete it.. but I dont see any of that happens ??!

    Thanks for the help.


    import java.io.*;

    public class example {

    public static void main (String args[]) {

    FileOutputStream out = new FileOutputStream("example.txt");

    out.write('H');
    out.write('E');
    out.write('L');
    out.write('L');
    out.write('O');
    // out.close() ... what happens if we dont call this method ??


    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    try it and see what happens. Don't exit the code by having a long sleep() before the exit and see if you can access the file from another program with the file still not closed.

    In general its better to close files and finish processing rather than leave it to someone else to do it for you.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. question
    By ayoood in forum Java Software
    Replies: 6
    Last Post: 07-07-2008, 02:32 PM
  3. JSP Question
    By maheshkumarjava in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 11:51 AM
  4. a question
    By slytheman in forum Java Servlet
    Replies: 0
    Last Post: 03-12-2008, 05:11 AM
  5. Need help on this question
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-27-2008, 04:58 PM

Posting Permissions

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