Original works can be reprinted. During reprinting, you must mark the original source, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://blog.csdn.net/love254443233/article/details/7972525
I have found a lot of information on modifying Java listening files on the Internet. Many of them are too complicated, and there are problems with using them locally. Here, you can write a simple method to modify the listening file. The Code is as follows:
Package COM. yunho. rule; import Java. text. simpledateformat; import Java. util. *; import Java. io. file; import Java. io. ioexception; public class filelistener {/*** a facility for threads to schedule tasks for future execution in a background thread. * tasks may be scheduled for one-time execution, or for repeated execution at regular intervals. **/private timer;/*** current time **/private long cur Required time =-1;/*** last modified time **/private long lastmodifiedtime =-1;/*** minute **/private long times = 1; /*** time **/private long pollinginterval = 1000 * times;/*** file path **/private string filepath = "src/COM/yunho/Rule/rule. XML "; Public filelistener () {file = new file (filepath); lastmodifiedtime = file. lastmodified (); currenttime = lastmodifiedtime;} public static void main (string [] ARGs) {fi Lelistener filelistener = new filelistener (); filelistener. timer = new timer (true); filelistener. start ();} public void start () {timer. schedule (New filemonitor (), 0, pollinginterval); While (true) {try {int CH = system. in. read (); system. out. println ("Ch =" + CH); If (CH-'c' = 0) {system. out. println ("quit"); timer. cancel (); break ;}} catch (ioexception e) {e. printstacktrace () ;}} private class filemonitor exte NDS timertask {public void run () {file = new file (filepath); lastmodifiedtime = file. exists ()? File. lastmodified ():-1; if (currenttime! = Lastmodifiedtime) {system. out. println ("file [" + file. getname () + "] changed at:" + new simpledateformat ("yyyy-mm-dd hh: mm: ss sss "). format (lastmodifiedtime); currenttime = lastmodifiedtime ;}}}}