|
import java.io.*;
import java.util.*;
class TestThreadFile implements Runnable {
public void run(){
//Date date=new Date();
File file1=new File("F:\\xie1.txt");
File file2=new File("F:\\xie2.txt");
Long time1=file1.lastModified();
Long time2=file2.lastModified();
while(true){
if(!(file1.exists())){
System.out.println("no File1");
}
if(!(file2.exists())){
System.out.println("no File2");
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(file1.lastModified()>time1||file2.lastModified()>time2){
System.out.println("change");
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(file1.lastModified()<=time1||file2.lastModified()<=time2){
System.out.println("no changed");
}}}}
public class TestThread extends Thread{
public static void main(String[] args) {
// TODO Auto-generated method stub
TestThreadFile ft=new TestThreadFile();
Thread thread1=new Thread(ft);
Thread thread2=new Thread(ft);
thread1.start();
thread2.start();
}} |
|