Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does FileReader block/ lock the file

 
Dave Jones
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 229
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both, I'll check it out
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic