It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Does FileReader block/ lock the file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does FileReader block/ lock the file" Watch "Does FileReader block/ lock the file" New topic
Author

Does FileReader block/ lock the file

Dave Jones
Ranch Hand

Joined: Feb 20, 2005
Posts: 77
Hello Ranchers !!
I'm reading a file into a StringBuffer, something like this-


Now, the file I'm reading from is updated by the System every minute or so, So I was wondering if the FileReader action locks the file until the reading is over, because otherwise the file might be updated while I'm reading from it an thus , my numbers won't be correct.
Thanks for your help,
Dave
Sanjaya Sugiarto
Ranch Hand

Joined: Mar 25, 2004
Posts: 229
I am not sure if it locks the file or not. But for safety just use Thread feature in order to make sure that there is only one thread process the file.


<a href="http://www.wi.hs-furtwangen.de" target="_blank" rel="nofollow">Business Information Technology - Hochschule Furtwangen University, Germany</a>
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Well the Java API Documentation says it is platform dependent.


[...] Some platforms, in particular, allow a file to be opened for writing by only one FileOutputStream (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open. [...]


I tested on Windows (not concurrently) and I could open to OutputStreams and an InputStream simultaneously. I wrote to both OutputStreams, and after that I did some reading and everyting went alright.

I wanted to tested on Linux, but I really need to go to have breakfast. So you have fun with it.

Best regards,
Edwin Dalorzo.
Dave Jones
Ranch Hand

Joined: Feb 20, 2005
Posts: 77
Thank you both, I'll check it out
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does FileReader block/ lock the file