• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write in text/doc file dynamiclly ?

 
mozammil muzza
Ranch Hand
Posts: 32
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am opening one text file (e.g. write.txt) using runtime and process class and again reading from some other text file (e.g. read.txt) line by line and then trying to write in same opened file i.e. write.txt. but here only i am facing problem. It is writer fine but i am not able to see this in opened file.
My Requirement is to see that text which thread is writing from other file i.e. read.txt, but it is not happening.
That's why i am saying this as dynamically.
Hope you all get my problem.
Please help to achieve this.

Note : For all of this i am using the thread which is scheduled for every 2 mins.

Thanks,
Muzza
 
Henry Wong
author
Marshal
Pie
Posts: 21420
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mozammil muzza wrote:Hi All,
I am opening one text file (e.g. write.txt) using runtime and process class and again reading from some other text file (e.g. read.txt) line by line and then trying to write in same opened file i.e. write.txt. but here only i am facing problem. It is writer fine but i am not able to see this in opened file.
My Requirement is to see that text which thread is writing from other file i.e. read.txt, but it is not happening.
That's why i am saying this as dynamically.
Hope you all get my problem.
Please help to achieve this.


Not a thread question. Maybe I should move this to the IO forum, but since the question is not well formed, let's look at it here.

Java IO is not that low level, and it is buffered. You can't have a reader instantaneous see the changes as you write them. There may be a way to implement it, but something tells me that is has to do with check the modification times, and reopening the file -- not sure.

Henry
 
Tim Moores
Bartender
Posts: 2895
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a dangerous thing to read and write a file from two processes (or two threads of the same process) simultaneously. A better solution would be to read the contents of the file into an appropriate data structure in memory, and access that in a properly synchronized manner. You could flush the data structure to disk after each change if that's important.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic