Comment detail

ファイル更新の監視 (Nested Flatten)
ファイルの存在チェックとタイムスタンプのチェックのみを1秒周期で行っています。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import java.io.File;

public class Sample {
    static final String filename = "./check";
    static final long INTERVAL = 1000; // 1 sec
    static final String MESSAGE = "modified!";

    public static void main(String[] args) throws InterruptedException {
        File checkFile = new File(filename);
        long lastModified = checkFile.lastModified();
        while (true) {
            Thread.sleep(INTERVAL);
            long lm2 = checkFile.lastModified();
            if (lastModified != lm2) {
                System.out.println(MESSAGE);
                lastModified = lm2;
            }
        }
    }
}

Index

Feed

Other

Link

Pathtraq

loading...