⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lastmodified.java

📁 本书属于《开发专家之 Sun ONE》系列丛书
💻 JAVA
字号:
【代码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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -