Example usage for java.io File setLastModified

List of usage examples for java.io File setLastModified

Introduction

In this page you can find the example usage for java.io File setLastModified.

Prototype

public boolean setLastModified(long time) 

Source Link

Document

Sets the last-modified time of the file or directory named by this abstract pathname.

Usage

From source file:Touch.java

public static void main(String[] args) {
    String[] names = new File(".").list();

    Date current = new Date();

    for (int i = 0; i < names.length; i++) {
        File f = new File(names[i]);
        f.setLastModified(current.getTime());
    }//from  w  w w  .j a  va  2 s.  c  o m
}

From source file:Main.java

public static void main(String[] args) {
    File file = new File("C:/ReadText.txt");
    System.out.println(file.lastModified());

    System.out.println(file.setLastModified(new Date().getTime()));
    System.out.println(new Date(file.lastModified()));
}

From source file:Main.java

public static void main(String[] args) {
    File f = new File("C:/test.txt");
    long millisec = new Date().getTime();

    // set last modified time
    boolean bool = f.setLastModified(millisec);

    System.out.println("lastModified() succeeded?: " + bool);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File fileToChange = new File("C:/myfile.txt");

    Date filetime = new Date(fileToChange.lastModified());
    System.out.println(filetime.toString());

    System.out.println(fileToChange.setLastModified(System.currentTimeMillis()));

    filetime = new Date(fileToChange.lastModified());
    System.out.println(filetime.toString());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    File file = new File("filename");

    long modifiedTime = file.lastModified();
    // 0L is returned if the file does not exist

    long newModifiedTime = System.currentTimeMillis();
    boolean success = file.setLastModified(newModifiedTime);
    if (!success) {
        // operation failed.
    }// w  w w. j a  va 2  s . c o  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File f = new File("name.txt");

    if (!f.exists()) {
        System.out.println("File not found.");
        return;//from  www .j a  va 2  s . c om
    }
    if (f.canRead())
        System.out.println("  Readable");
    else
        System.out.println("  Not Readable");

    if (f.canWrite())
        System.out.println("  Writable");
    else
        System.out.println("  Not Writable");
    System.out.println("  Last modified on " + new Date(f.lastModified()));

    long t = Calendar.getInstance().getTimeInMillis();
    if (!f.setLastModified(t))
        System.out.println("Can't set time.");

    if (!f.setReadOnly())
        System.out.println("Can't set to read-only.");

    if (f.canRead())
        System.out.println("  Readable");
    else
        System.out.println("  Not Readable");

    if (f.canWrite())
        System.out.println("  Writable");
    else
        System.out.println("  Not Writable");
    System.out.println("  Last modified on " + new Date(f.lastModified()));

    if (!f.setWritable(true, false))
        System.out.println("Can't return to read/write.");

    if (f.canRead())
        System.out.println("  Readable");
    else
        System.out.println("  Not Readable");

    if (f.canWrite())
        System.out.println("  Writable");
    else
        System.out.println("  Not Writable");
}

From source file:IndexService.IndexServer.java

public static void main(String[] args) {
    File stop = new File("/tmp/.indexstop");
    File running = new File("/tmp/.indexrunning");
    if (args != null && args.length > 0 && args[0].equals("stop")) {
        try {//from  w w w .ja va  2s . c  o m
            stop.createNewFile();
            running.delete();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return;
    }

    if (running.exists() && (System.currentTimeMillis() - running.lastModified() < 15000)) {
        long time = running.lastModified();
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (running.lastModified() == time) {
            running.delete();
        } else {
            return;
        }
    }

    if (stop.exists()) {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (stop.exists())
            stop.delete();
    }

    Configuration conf = new Configuration();
    IndexServer server = new IndexServer(conf);
    if (args != null && args.length > 0 && args[0].equals("test")) {
        server.testmode = true;
    }
    server.start();
    try {
        running.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    new UserCmdProc(server).start();

    while (true) {
        stop = new File("/tmp/.indexstop");
        if (stop.exists()) {
            server.close();
            running.delete();
            stop.delete();
            break;
        }
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }

        running.setLastModified(System.currentTimeMillis());

    }
}

From source file:Main.java

public static void updateFileTime(File file) {
    long newModifiedTime = System.currentTimeMillis();
    file.setLastModified(newModifiedTime);
}

From source file:Main.java

private static void lastAccess(File file) {
    long now = System.currentTimeMillis();
    file.setLastModified(now);
}

From source file:Main.java

public static void updateFileTime(String dir, String fileName) {
    File file = new File(dir, fileName);
    long newModifiedTime = System.currentTimeMillis();
    file.setLastModified(newModifiedTime);
}