Friday 11 November 2016

Java Tutorial : Java IO (Java File - How to Get the file last modified date)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=XHFTyNV-oVo&list=UUhwKlOVR041tngjerWxVccw

FileDemo.java
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;

public class FileDemo
{

    public static void main(String[] args) throws IOException
    {
        File file = new File("D:/work/myfile.txt");

        /*
         * Returns the time that the file denoted by this
         * abstract pathname was last modified.
         * 
         * Returns: A long value representing the time the
         * file was last modified, measured in milliseconds
         * since the epoch (00:00:00 GMT, January 1, 1970),
         * or 0L if the file does not exist or if an I/O
         * error occurs
         */
        long lastModified = file.lastModified();
        System.out.println("Before Format : " + lastModified);

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
                                                "MM/dd/yyyy HH:mm:ss");

        String formatedStr = simpleDateFormat.format(lastModified);
        System.out.println("After Format : " + formatedStr);
    }

}
Output
Before Format : 1477106762355
After Format : 10/22/2016 08:56:02
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_File_lastModified_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_File_lastModified_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/882ffbbbc9c8fbb765fb4869059bc3ee253ad31b/BasicJava/JavaIODemo_File_lastModified_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment