adsense


Showing posts with label JAVA EXAMPLES SETTING FILE DATE. Show all posts
Showing posts with label JAVA EXAMPLES SETTING FILE DATE. Show all posts

Tuesday, 27 October 2015

JAVA EXAMPLES SETTING FILE DATE PAGE 96

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES SETTING FILE DATE



Java Examples - Setting File Date



Problem Description:
How to change the last modification time of a file ?
Solution:
This example shows how to change the last modification time of a file with the help of fileToChange.lastModified() and fileToChange setLastModified() methods of File class .
import java.io.File;
import java.util.Date;

public class Main {
   public static void main(String[] args) 
   throws Exception {
      File fileToChange = new File
      ("C:/myjavafile.txt");
      fileToChange.createNewFile();
      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());
   }
}
Result:
The above code sample will produce the following result.The result may vary depending upon the system time.
Sat Oct 18 19:58:20 GMT+05:30 2008
true
Sat Oct 18 19:58:20 GMT+05:30 2008


Monday, 26 October 2015

JAVA EXAMPLES SETTING FILE DATE PAGE 95

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES SETTING FILE DATE




Java Examples - Setting File Date


Problem Description:
How to change the last modification time of a file ?
Solution:
This example shows how to change the last modification time of a file with the help of fileToChange.lastModified() and fileToChange setLastModified() methods of File class .
import java.io.File;
import java.util.Date;

public class Main {
   public static void main(String[] args) 
   throws Exception {
      File fileToChange = new File
      ("C:/myjavafile.txt");
      fileToChange.createNewFile();
      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());
   }
}
Result:
The above code sample will produce the following result.The result may vary depending upon the system time.
Sat Oct 18 19:58:20 GMT+05:30 2008
true
Sat Oct 18 19:58:20 GMT+05:30 2008