0

I'm trying to make a basic chat program using Java. I want to know if it's possible to make a method that executes code once a certain text file has been edited. Every time somebody types in the chat, the message is sent into a text file. I want it to be able to read a message from the text file every time it's edited. I know how to do everything except the method that could execute every time this certain text file is edited.

Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34
  • possible duplicate of [Is there an async way of knowing a file has changed?](http://stackoverflow.com/questions/6946079/is-there-an-async-way-of-knowing-a-file-has-changed) – Mmmh mmh Dec 10 '14 at 13:58
  • `"Every time somebody types in the chat, the message is sent into a text file."` - Get ready for some race conditions... – David Dec 10 '14 at 13:58
  • @AurélienOoms that link in for C++... – assylias Dec 10 '14 at 13:58
  • https://docs.oracle.com/javase/tutorial/essential/io/notification.html – assylias Dec 10 '14 at 13:59
  • "Every time somebody types in the chat, the message is sent into a text file". So every time somebody types something, your file will be changed. So, at that moment you can capture the information of the text. Now, you must do it depending on what you need, before the file being edited or after being edited. If you need it before, you should invoke the method as soon as the user entered something in the chat. If you need it after, you should invoke it after the change is written. – Marcelo Tataje Dec 10 '14 at 14:43
  • I would need it after the change is written, what would the code be for that situation. – jordsta95 Dec 11 '14 at 13:57

0 Answers0