top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to get last updated file in a directory using Java?

+2 votes
90 views
How to get last updated file in a directory using Java?
posted Jan 5, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
/*
  Get Last modification time of a file or directory
  This Java example shows how to determine last modification time of a particular
  file or directory using lastModified method of Java File class.
*/

import java.io.*;
import java.util.Date;

public class GetLastModificationTimeOfAFile {

  public static void main(String[] args) {

    //create file object
    File file = new File("C://FileIO//demo.txt");

    /*
     * To determine last modification time of a particular file or directory, use
     * long lastModified() method of Java File class.
     *
     * This method returns long representing the time file was last modified as
     * milliseconds since Jan 01, 1970 00:00:00. This
     * method returns 0L if the file does not exists or in case of IOException.
     *
     */

     long lastModified = file.lastModified();

     System.out.println("File was last modifed at : " + new Date(lastModified));
  }
}

/*
Typical output would be
File was last modifed at : Sun Jan 06 18:24:01 EST 2008
*/
answer Jan 8, 2016 by Karthick.c
Similar Questions
+1 vote

I have a web application developed using Struts2. In my web application I have a link using which users can download a zip file. I need to create this zip file at run time based on some conditions. How can I do this in Struts2?

0 votes

My collection is like this, but I want to update a nested object with {"env":"qa"} in my updated collection with java-driver:

{ "_id" : ObjectId("5b052eeff9290437b217b1ed"), "app" : "hike", "group" : [ { "env" : "prod" }, { "env" : "test" } ]}{ "_id" : ObjectId("5b052f36f9290437b217b1ee"), "app" : "viber", "group" : [ { "env" : "prod" }, { "env" : "test" } ]}

+2 votes

Rohit wants to add the last digits of two given numbers.
For example, If the given numbers are 267 and 154, the output should be 11.

Below is the explanation -
Last digit of the 267 is 7
Last digit of the 154 is 4
Sum of 7 and 4 = 11

Write a program to help Rohit achieve this for any given two numbers.

Note: The sign of the input numbers should be ignored. i.e.
if the input numbers are 267 and 154, the sum of last two digits should be 11
if the input numbers are 267 and -154, the sum of last two digits should be 11
if the input numbers are -267 and 154, the sum of last two digits should be 11
if the input numbers are -267 and -154, the sum of last two digits should be 11

...