Results 1 to 2 of 2

Thread: one simple question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    faridabad
    Posts
    101

    one simple question

    hi,

    That is what i am asking how i will get the last modified date and how i will compare them


    ishikha
    ishikha

  2. #2
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I wasnt sure what criteria you wanted to use in the comparision process so i just coded an example of getting the last modified dates for the files specified. Also im not sure if you know but the modification date changes when class files are recompiled even if they have not been been modified.
    PHP Code:
        import java.io.*;
      
    import java.util.Date

      class 
    FileCompare {
        public static 
    void main(String[] args){

        
    BufferedReader buff;
        
    String file1 null
        
    String file2 null
        
    buff = new BufferedReader(new InputStreamReader(System.in));
         
       try{
        
    System.out.println("Please enter the first file to compare"); 
        
    file1 buff.readLine();
        
    System.out.println("Please enter the second file to compare");  
        
    file2 buff.readLine(); 
       }catch(
    Exception e){System.err.println(e);}
        
    compareFiles(file1,file2); 
      }
      public static 
    void compareFiles(String file1String file2){
        
        
    File f1 = new File(file1); 
        
    File f2 = new File(file2);
        if(
    f1.isFile() && f2.isFile()){ 
         
    Date d1 = new Date(f1.lastModified()); 
         
    Date d2 = new Date(f2.lastModified());
         
    System.out.println(d1);
         
    System.out.println(d2);
         }else{
    System.out.println("Only files must be specified");}
        }
       } 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width