Created
May 15, 2012 14:51
-
-
Save chalstrick/2702364 to your computer and use it in GitHub Desktop.
Test Filesystem: difference between System.currentTimeMillis() and File.getLastModified().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.IOException; | |
public class TestFileSystem { | |
private static final int NR_OF_FILES = 1000; | |
public static void main(String[] args) throws IOException { | |
File tmpDir = new File(System.getProperty("java.io.tmpdir"), "tmp" | |
+ System.currentTimeMillis()); | |
tmpDir.mkdirs(); | |
try { | |
long[] timestamps = new long[NR_OF_FILES + 1]; | |
for (int i = 0; i < NR_OF_FILES; i++) { | |
timestamps[i] = System.currentTimeMillis(); | |
File f = new File(tmpDir, String.valueOf(i)); | |
f.createNewFile(); | |
} | |
for (int i = 0; i < NR_OF_FILES; i++) { | |
File f = new File(tmpDir, String.valueOf(i)); | |
System.out.println("File #" + i | |
+ ": System timer when creating file: " + timestamps[i] | |
+ ".\t lastModified of created file:" | |
+ f.lastModified()); | |
} | |
} finally { | |
delete(tmpDir); | |
} | |
} | |
static void delete(File f) { | |
if (f.isDirectory()) | |
for (File c : f.listFiles()) | |
delete(c); | |
f.delete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment