lastmodified.java
来自「java2应用开发指南第一版」· Java 代码 · 共 46 行
JAVA
46 行
【代码7-3-2】
//LastModified.java
import java.io.*;
class LastModified
{
public static void main(String[] args)
{
try
{
File temp = File.createTempFile("jcl", ".out");
// Make sure it gets deleted when we're done
temp.deleteOnExit();
// Print out file name and its last modified time
long mod = temp.lastModified();
System.out.println(temp + ":" + mod);
// Introduced some delay
try
{
Thread.sleep(3000);
}
catch (InterruptedException ie)
{
};
// Write something out to file
FileWriter fout = new FileWriter(temp);
fout.write("hello");
fout.close();
System.out.println(temp + ":" + temp.lastModified());
// Change modified date back to original
if (temp.setLastModified(mod))
{
System.out.println(temp + ":" + temp.lastModified());
}
else
{
System.out.println("modification time unchanged");
}
//
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?