Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Change a file timestamp 
 

Timestamp is a utility to change or modify the time of a file. Java provides the facility for changing a file timestamp according to the user reliability.

 

Change a file timestamp 

                         

Timestamp is a utility to change or  modify the time of a file. Java provides the facility for changing a file timestamp according to the  user reliability.  

Description of program:

This program helps you in changing a file timestamp or modification time in Java. After running this program it will take a file name and its modification date in 'dd-mm-yyyy' format. Then it will check the given file is exist or not using the exists() method. When the file exists, this program will change the date of given file and it will display a message "Modification is successfully!" otherwise it will show "File does not exists!".

Description of code:

setLastModified(long time):
This is the method that sets the last modification time of a file or directory and returns Boolean types values either 'true' or 'false'. If it will  return a 'true' only
when the modification is completely successfully otherwise, it will return 'false'. This method takes following long type data:

        time: This is the time that have to be modified or set. 

getTime():
This is the method that returns the number of milliseconds in GMT format like: 23-04-2007.

Here is the code of program:

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

import java.text.*;


public class ChangeFileDate{
 
  
public static void main(String[] args) {
 
    
try{
 
     
System.out.println("Change file timestamp example!");
      BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("Enter file name with extension:");
 
      
String str = bf.readLine();
      System.out.println("Enter last modified date in 'dd-mm-yyyy' format:");
      String strDate = bf.readLine();
 
     
SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy");
 
     
Date date = sdf.parse(strDate);
  
    
File file = new File(str);
 
      
if (file.exists()){

        file.setLastModified(date.getTime());
 
       
System.out.println("Modification is successfully!");
   
   
}

      else{

        System.out.println("File does not exists!");

      }
   
 
}

    catch(Exception e){
 
     
e.printStackTrace();

    }
  
}

}


Output of program:

C:\vinod\Math_package>javac ChangeFileDate.java

C:\vinod\Math_package>java ChangeFileDate
Change file timestamp example!
Enter file name with extension:
StrStartWith.shtml
Enter last modified date in 'dd-mm-yyyy' format:
23-04-2007
Modification is successfully!

Download this example.

                         

» View all related tutorials
Related Tags: c orm form time script object io objects help method sed system ip collection this opera create show for work

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

please sand me procidure of creating time stamp in jsp

Posted by nibash on Friday, 09.26.08 @ 18:51pm | #80724

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.