Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
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.  

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.

                         

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

Latest Searches:
Telephony
message box display in
Binome
Authentication Filters
how to iterate a linke
compare two arraylist
jsf tree node set hr
get url
ajax auto complete
jar entry
diff. shape of linear
Photoshop Web Layouts
advantages of jsp over
jsp method
Struts Projects
tax calculator
Passing Parameters in
FlowLayout
JDBC-ODBC
<form: checkbox path=
Treemap using gwt tree
draw Polyline
comparable
jsp with strutsframewo
selecting option value
struts-servlets.xml
generate report in exc
FIFO
java example program t
pagination using javas
how to write in pdf us
Insert an array list o
stored procedure debug
log4j
program in java to ins
IBM MQ server
Hibernate Min() Functi
increase size of strut
JConfig
java drivers use to co
Java Mysql
send email
Javascript Date and Ti
dojo debug
code to add and retriv
source code for edit e
explaination of JDBC u
how retrive a data fro
Photoshop Write messag
capture screen j2me
java programming with
Custom Iterator Tag in
sort compareTo
how to display an imag
capture image
struts tld downloas
clientside validations
J2ME and WAP
JScrollPane
html code for developi
HSSF clone cell
c:out in var of c:fore
getwindowwidthandheigh
getNumericValue
how to pass same varia
jsp trim char
array element in php
decimal to aski
Introduction to jquery
connect SQL server in
match move
how to create war file
abstract of product ma
href
life cycle of java ser
tabindex
jsp ajax dynamically l
client/server computin
xls
checkbox button enable
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.