• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading file that is updated while reading

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading a file that is being updated by another app while the reader is reading. I read to the end, then go to sleep for a couple of seconds, then look for new data. I am using BufferedReader in a while loop, and readLine() to get the data. Is there a way to read to the end of the file, then wait until the reader 'wakes up' when something new is there, rather than having to sleep?
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brad,
How is it possible to read and update a file at the same time.I don't think its logical to do so.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you considered the possibility of using piped streams. They seem to be perfect for this kind of problem.

They work in different threads, one side is writing into the pipe, the other side is reading from it. If there are not bytes available, the second pipe waits until there is something available. Once there is something available it reads again.
 
Brad Walton
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I won't ever be writing to this file. A different app is writing to the file (log file), and I need to read it in real-time. The pipe-streams are a possibility. I thought there might be a part of the I/O that handles reading in this manner, but had not found it yet.

Thanks for your suggestion.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I'm not mistaken, the Unix "tail -f" command does exactly that. So if you're using Unix you could pipe the output of tail -f into your program.
 
Brad Walton
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not Unix-specific, but thanks.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just got curious and googled for "windows tail"
People seem to be doing some work on this!
This article claims that a tail command is available as part of Windows 2003 Resource Kit!
I really was not curious enough to go through all the links but may be you can try your luck!
 
reply
    Bookmark Topic Watch Topic
  • New Topic