Results 1 to 4 of 4

Thread: one simple question

  1. #1

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

    one simple question

    hi friends,

    there is one problem.in java there are source file and there objects are made when we compile it.now i want to compare the date of source file and the object and find out which one is later modified.

    plz help me i am a beginner

    my code is:


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


    public class MileStone1
    {

    public static void main(String args[])
    {

    System.out.println("<html><head></head><body><table width=100%>");

    MileStone1 m1=new MileStone1();
    m1.getDir(args[0]);

    System.out.println("</table></body></html>");

    }

    public Vector getJava(String path)
    {

    Vector javaFile=new Vector();

    try{
    file f = new File(path);
    String dirList[] = f.list();


    for (int i = 0; i < dirList.length; i++) {

    if(dirList[i].indexOf("java") != -1)
    {

    System.out.println("<tr>");
    javaFile.addElement(dirList[i]);

    Vector objs=getObjects(dirList[i],path);

    System.out.println("<td width=25%>"+dirList[i]+"</td>");

    System.out.println("<td width=25%>"+path+"</td>");
    String classes_name="";

    for(int k=0;k < objs.size(); k++)
    {
    // System.out.println(objs.elementAt(k));
    classes_name = classes_name + objs.elementAt(k) +"\r\n";

    }

    System.out.println("<td width=25%>"+classes_name+"</td>");
    System.out.println("<td width=25%>"+path+"</td>");
    System.out.println("</tr>");
    }

    }


    }catch(Exception ex){System.out.println("Get Java"+ex);}
    return javaFile;

    }

    public Vector getObjects(String sourceName,String path)
    {
    Vector objects=new Vector();
    sourceName =sourceName.substring(0,sourceName.indexOf("."));
    try{
    File f = new File(path);
    String dirList[] = f.list();


    for (int i = 0; i < dirList.length; i++) {

    // System.out.println("ssss"+sourceName+".class") ;

    if((dirList[i].indexOf(sourceName+".class") != -1))
    {
    // System.out.println("in adding class"+dirList[i]) ;
    objects.addElement(dirList[i]);

    }
    else
    {
    if((dirList[i].indexOf(sourceName) != -1) && (dirList[i].indexOf("java") == -1) && (dirList[i].indexOf("$") != -1))
    {

    // System.out.println("in adding class1"+dirList[i]) ;
    objects.addElement(dirList[i]);
    }
    }

    }
    }catch(Exception ex){System.out.println("Get Objects"+ex);}
    return objects;

    }

    public void getDir(String baseFile)
    {

    try{
    FileInputStream fis=new FileInputStream(baseFile);
    DataInputStream dis=new DataInputStream(fis);
    String dir=" ";
    while(dir != null)
    {
    dir =(String) dis.readLine();
    getDocument(dir);
    }

    }catch(Exception ex){System.out.println("Get Dir"+ex);}


    }

    public void getDocument(String path)
    {
    Vector javaFile= getJava(path);
    }


    }


    regards
    ishikha
    ishikha

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Ummm...just look at the last modified date of the .java file vs the last modified date of the .class file.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    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 modified date of both and how i will compare them

    ishikha
    ishikha

  4. #4
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    I think what you are saying is the following:

    You have two files, (types really dont matter, they are just files), you want to compare the the last modified date of each file and then take appropriate action?

    The last modified date of a file can be easily obtained via the lastModified() function of the file class. lastModified() returns the time that the file denoted by this abstract pathname was last modified. You can then do a comparision on that number to see which is newer. Hint: The bigger the number, the newer the file.

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