Results 1 to 3 of 3
Thread: FileOutputStream question...
- 07-07-2008, 12:56 AM #1
Member
- Join Date
- Nov 2007
- Posts
- 20
- Rep Power
- 0
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 ??
}
}
- 07-07-2008, 02:49 AM #2
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.
- 07-07-2008, 05:30 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes try and see. As Norm says, always better to looking for safe exist on the application. That's why you have to properly close all the opened files.
Similar Threads
-
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
question
By ayoood in forum Java SoftwareReplies: 6Last Post: 07-07-2008, 01:32 PM -
JSP Question
By maheshkumarjava in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-29-2008, 10:51 AM -
a question
By slytheman in forum Java ServletReplies: 0Last Post: 03-12-2008, 04:11 AM -
Need help on this question
By Deon in forum New To JavaReplies: 3Last Post: 01-27-2008, 03:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks