0

If we open a file with my java application and open the same file with another application and made some changes. The java application I made, should know it immedeately that this file is changed by some external application, and prompt the user to load the fresh content.
How to do it using java?

Ranjan Sarma
  • 1,565
  • 5
  • 22
  • 36

3 Answers3

2

This question is asked before here

https://stackoverflow.com/questions/5379458/java-filewatcher

read this http://docs.oracle.com/javase/tutorial/essential/io/notification.html

Community
  • 1
  • 1
Sap
  • 5,197
  • 8
  • 59
  • 101
1

You can make check in this handler:

frame.addWindowFocusListener(new WindowAdapter() {
    public void windowGainedFocus(WindowEvent e) {
        // TODO: read file again and compare with previous 
    }
});
CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
0

I think you have to have thread that polls for file information. See this question File changed listener in Java.

Community
  • 1
  • 1
The Cat
  • 2,375
  • 6
  • 25
  • 37