× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Title: File.setLastModified()

We're using a program on PCs that checks for updated files on the server using HTTP  Get if-modified-since, passing the file's date.   The problem is for users using the old FAT file system, the file time has a resolution of two seconds, rounding down.  So if a file on the server has an odd number of seconds, the file will be transfered every time. (Say time of file on server is 12:04:37, it will become 12:04:36 on the PC so the If-Modified-Since will always be true.)  I jave no control on the PC program or the file system of the users.

I'm trying to set the modified time of files created on the server to an even number of seconds using setLastModified but the results is that the file time is always set to midnight on January 1st 1970.

Here's an example:

import java.io.* ;                                 
import java.util.Date ;                            
                                                   
public class   EvenTime                            
{                                                  
 public static void main( String[] args )          
 {                                                 
  if (args.length < 1)                             
  {                                                
   System.out.println("Usage: EvenTime FileName") ; 
   System.exit(2) ;                                
  }                                                
  File aFile = new File( args[0] ) ;             
                                                   
// get current file time                           
  long ficTime = aFile.lastModified() ;          
  Date ficDate = new Date( ficTime) ;              
  System.out.println( ficDate.toString() ) ;                    
  System.out.println( ficTime ) ;                               
                                                                
// insure an even number of seconds (round down)                
  long newTime = ficTime - (( (ficTime / 1000) % 2 ) * 1000 );  
  Date newDate = new Date( newTime) ;                           
  System.out.println( newDate.toString() ) ;                    
  System.out.println( newTime ) ;                               
  aFile.setLastModified( newTime ) ;                          
                                                                
// test results                              
  long tstTime = aFile.lastModified() ;    
  Date tstDate = new Date( tstTime) ;        
  System.out.println( tstDate.toString() ) ; 
  System.out.println( tstTime ) ;            
                                             
  System.exit(0) ;                           
 } // main                                   
}                                            


Here's a sample run (I use the touch utility to reset the file time to the current time.)

touch test.txt                            
$                                         
java -Djava.version=1.2 EvenTime test.txt 
Mon Apr 02 19:23:05 GMT+00:00 2001        
986239385000                              
Mon Apr 02 19:23:04 GMT+00:00 2001        
986239384000                              
Thu Jan 01 00:00:00 GMT+00:00 1970        
0                                         


I have full access to the test file (the file _is_ changed, simply not to the value I want).
I've also tried to set a time in the future but the results are the same.
I don't understand why it does not work, then again I'm new to this Java thing.

Thank you.
Thierry.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.