Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Change a file TimeStamp in Java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 30-11-2009
Member
 
Join Date: Nov 2009
Posts: 580
Change a file TimeStamp in Java
  

Hi, can anyone know how to Change a file TimeStamp with the help of Java? I want to do this and if you have any idea then please reply me that. I am waiting for your reply. And think that it will be easy to understand. Just reply as soon as possible as I am waiting.

Reply With Quote
  #2  
Old 30-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Change a file TimeStamp in Java

Hi, it is not possible to me what you are asking about. What is the Timestamp in java? I have never heard about this. If you have details about this, please forward me also. I am waiting for your reply. I had searched this on internet, but cant find anything about it. Where did you find all this stuff. Just give me also the source code if you got, so I can able to get it. I am also waiting for the reply to this question so that I can get knowledge about it.
Reply With Quote
  #3  
Old 30-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: Change a file TimeStamp in Java

Hi, as far as I have knowledge you can change the timestamp of the file with the help of the following code. Try to use it, modify it if you want.

Code:
import java.io.*;
import java.util.*;
import java.text.*;

public class ChangeTimeStamp
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader bfreader = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("Enter the file name with extension:");
			String string = bfreader.readLine();
			System.out.println("Enter last modified date in 'dd-mm-yyyy' format:");
			String strDate = bfreader.readLine();
			SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy");
			Date date = sdf.parse(strDate);
			File file = new File(string);
			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();
		}
	}
}
Reply With Quote
  #4  
Old 30-11-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Change a file TimeStamp in Java

Hi, I don't know how to do this, but I have got some code which will help you to do different types of changes in your file as you want. Hope one of the method from code below will help you.

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Date;

public final class TestFile
{
private static void testFileFileManipulationMethods() throws IOException
{
System.out.println( "Testing File name-getting methods." );
System.out.println("There must exist a TEST file called E:\\genus\\species\\crocdile.html" );
File f = new File( "E:\\genus\\species\\crocodile.html" );
if ( f.exists() )
{
System.out.println( "file exists" );
}
System.out.println( "file is " + f.length() + " bytes long" );
File dir = new File( "E:\\genus\\species" );
String[] files = dir.list();
System.out.println( "Files in this directory are:" );
for ( String file : files )
{
System.out.println( file );
}
System.out
.println( "file "+ ( f.canRead() ? "can" : "cannot" + " be read" );

System.out.println( "file "+ ( f.canWrite() ? "can" : "cannot" )+ " be written" );
System.out.println( "last modified: " + new Date( f.lastModified() ) );
System.out.println( "file "+ ( f.isDirectory() ? "is" : "is not" )+ " a valid existing directory" );
System.out.println( "file "+ ( f.isFile() ? "is" : "is not" )+ " a valid existing file" );
File[] roots = File.listRoots();
for ( File root : roots )
{
System.out.println( root );
}
File dirs = new File( "C:\\temp\\silly\\preposterous" );
System.out.println( "success in creating directory tree: "+ dirs.mkdirs() );
File dirOneLevel = new File( "C:\\temp\\absurd" );
System.out.println( "success in creating one directory level: "+ dirOneLevel.mkdirs() );
RandomAccessFile raf = new RandomAccessFile( new File("E:\\genus\\species\\rabbit.html" ), "rw" );
raf.setLength( 50 );
f.setReadOnly();
f.setLastModified( System.currentTimeMillis() - ( 24 * 60* 60 * 1000 ) );
}
private static void testFileNameGettingMethods() throws IOException
{
System.out.println( "Testing File name-getting methods." );
System.out.println("There must exist a TEST file called E:\\genus\\species\\crocdile.html" );
System.out.println( "The current directory must be E:\\genus" );
File currentDirectory = new File( "." );
System.out.println( "dir: " + currentDirectory.getCanonicalPath() );
System.out.println( "Using relative name" );
File f = new File( "species/CROCODILE.HTML" );
System.out.println( "toString: " + f.toString() );
System.out.println( "absolutePath: " + f.getAbsolutePath() );
System.out.println( "name: " + f.getName() );
System.out.println( "path: " + f.getPath() );
System.out.println( "parent: " + f.getParent() );
System.out.println( "canonicalPath: " + f.getCanonicalPath() );
System.out.println( "Using absolute name" );
f = new File( "E:\\genus\\species\\CROCODILE.HTML" );
System.out.println( "toString: " + f.toString() );
System.out.println( "absolutePath: " + f.getAbsolutePath() );
System.out.println( "name: " + f.getName() );
System.out.println( "path: " + f.getPath() );
System.out.println( "parent: " + f.getParent() );
System.out.println( "canonicalPath: " + f.getCanonicalPath() );
System.out.println( "Using relative name with drive" );
f = new File( "e:species\\CROCODILE.HTML" );
System.out.println( "absolutePath: " + f.getAbsolutePath() );
System.out.println( "name: " + f.getName() );
System.out.println( "parent: " + f.getParent() );
System.out.println( "path: " + f.getPath() );
System.out.println( "canonicalPath: " + f.getCanonicalPath() );
}
private static void testTemporaryFiles() throws IOException
{
File temp = File.createTempFile( "temp", ".tmp", new File( "C:\\temp" ) );
temp.deleteOnExit();
System.out.println( "Success of delete: " + temp.delete() );
}
public static void main( String[] args ) throws IOException
{
testFileFileManipulationMethods();
testFileNameGettingMethods();
testTemporaryFiles();
}
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Change a file TimeStamp in Java"
Thread Thread Starter Forum Replies Last Post
How to print filled/last edited timestamp of the pdf file on Adobe Acrobat Bozidar Windows Software 3 12-11-2011 05:03 PM
Changing timestamp of file in linux Levi-Fevi Operating Systems 4 18-02-2010 10:13 PM
How to change the Look and Feel in Java? Bigga Lexx Software Development 5 14-02-2010 12:55 AM
Administrator can't get file ownership or change file permissions Franseza Window 2000 Help 1 29-07-2007 08:01 PM


All times are GMT +5.5. The time now is 07:09 PM.