Unclosed File input stream , Any performance implications?
Hi,
I open a file input stream as below and read the contents of a file and exit from the method without closing the input stream [fin.close()].
1) What are the implications of not closing input stream, performance related?.
2) Since fin is a local variable once the method terminates the variable will be destroyed, In this do i still need to close the input stream?
FileInputStream fin = new FileInputStream(file);
Please advice.
Thanks
Deepak
I want to know what excatly will happen when i dont close.
I did a google and saw it will result in file descriptor leak, But i was not able to find "What is file descriptor leak?" , Also i want to know any other potential performance issues with this?
Please reply.
It might lock the file.
Also, I accidentally forgot to close a writer the other day at work
and it caused a bug that drove me crazy. Because I never closed it
the write buffer never flushed() out completely.
Hi,
It was just a question , I wanted to know the implications of not closing.
1) Will below code lock the file and then not closing the connection will cause a error?
2) Does opening the file in read only mode cause the file to be locked so that it cannot be opened for reading or writing later?
FileInputStream fin = new FileInputStream(file);
Java doc:
Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system. A new FileDescriptor object is created to represent this file connection.
> Hi,
> It was just a question , I wanted to know the
> implications of not closing.
>
> 1) Will below code lock the file and then not closing
> the connection will cause a error?
Trying to open the file can cause an error if there are too many open file descriptors.
> 2) Does opening the file in read only mode cause the
> file to be locked so that it cannot be opened for
> reading or writing later?
Probably not, but it can still cause an error, see above.
Kaj
kajbja at 2007-7-29 16:30:03 >
