is it important to close a file thats been opened with FileWriter? if yes how come??

Recommended Answers

All 2 Replies

It can't hurt so when in doubt, do it. As far as I know the only possible consequence is that no other file will be able to open the file for writing until you close the FileWriter, but I also suspect that garbage collection might cause the FileWriter to relinquish its resources as part of the garbage collection process anyway. Again, those are my suspicions, do not take them as fact. But do know that only one thread at a time can have a file open for writing, so if your FileWriter is not closed, you haven't given that resource back to the OS, and as a result, nobody else can write to the file while it is open.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.