package com.softeem.thread.test; import java.io.File; public class HomeWork2 implements Runnable { private File file=null; long l=0; public String getP() { String path=null; path=file.getPath(); return path; } public void setFile(String path) { file=new File(path); } //File file=new File(); public void run() { // TODO Auto-generated method stub l=this.file.lastModified(); while(true) { try { Thread.currentThread().sleep(1000); if(l!=this.file.lastModified()) { System.out.println("file has beaning changed......"); } l=this.file.lastModified(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub HomeWork2 c=new HomeWork2(); c.setFile("E:/新建文件夹 (2)/123.txt"); new Thread(c,"thread0").start(); } }