Results 1 to 5 of 5
  1. #1
    rhub is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default .java files comparsion

    I would like to know, how can I comparse two .java files.
    Thanks for responding

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    rhub is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default

    I want compare existing java file with genereted java file. I want it to make structural comparsion. I mean if the files has different order of imports or methods, it will tell me, that the files are equal.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Ok, you have to user BufferedReader for this. Actually two of the for two files. Then read both files into two different BufferedReader streams. Now you have two streams. What you have to do now is, tokernize both of them, in that way you can find two string arrays. Simply compare both arrays. That's all.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    make structural comparsion.
    Sounds like a tough problem to do at the source level. If you take any source program and move the methods or variable definitions around, then comparing that with the original program will be very hard. Lots of lines of code can be reordered without effecting the execution results.
    But if compiling the two programs generate the SAME bytecode, could that be used to solve the problem? But if two statements are in different order this method would fail.

Similar Threads

  1. Batch Files in java
    By coco in forum New To Java
    Replies: 3
    Last Post: 12-05-2008, 01:30 PM
  2. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM
  3. conversion of java .class files to .java files
    By kotturupraveen in forum New To Java
    Replies: 2
    Last Post: 06-09-2008, 12:58 PM
  4. error in Java files
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 12:14 PM
  5. How to search files with Java
    By karma in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 01:25 PM

Posting Permissions

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