How to compare two files in Java & uncommon text should print in Diff text

Hi All,
can any one help me to write a java program..
How to compare two files in Java & uncommon text should print in Diff text file..
Thanks
Sam

Hi All,
i m comparing two HTML file.. thats why i am getting problem..
import java.io.BufferedReader;
import java.io.FileReader;
public class textmatch{
public static void main(String[] argv)
throws Exception{
BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
String s;
String y;
while ((s=fh.readLine())!=null)
if ( s.equals(y=sh.readLine()) ){    
System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
sh.close();
fh.close(); }
thanks
Sam

Similar Messages

  • How to compare two files in java & uncommon text should print in text file.

    Hi,
    Can any one help me to write Core java program for this.
    How to compare two files in java & uncommon text should print in other text file.
    thanks
    Sam

    Hi All,
    i m comparing two HTML file.. thats why i am getting problem..
    import java.io.BufferedReader;
    import java.io.FileReader;
    public class textmatch{
    public static void main(String[] argv)
    throws Exception{
    BufferedReader fh =new BufferedReader(new FileReader("internal.html"),1024);
    BufferedReader sh = new BufferedReader(new FileReader("external.html"),1024);
    String s;
    String y;
    while ((s=fh.readLine())!=null)
    if ( s.equals(y=sh.readLine()) ){    
    System.out.println(s + " " + y); //REMOVE THIS PRINTLN STATEMENT IF YOU JUST WANT TO SHOW THE SIMILARITIES
    sh.close();
    fh.close(); }
    thanks
    Sam

  • How to compare two files using MD5?

    Hi,all:
    How to compare two files to know if they're the same without any difference?I want to use MD5, but I just konw how get a message digest of a string. How to get a message digest of a file? Or there is other method to compare two files?
    Thanks advance!

    This is starting to sound rather a lot like a homework problem.
    An MD5 message digest is simply a 16 byte array. To compare two message digests...
    byte[] md5incoming = ...
    byte[] md5comparison = ...
    if( md5incoming.equals(md5comparison) ) {
       System.out.println("MD5 Checksums match");
    }To find out how to generate an MD5 checksum, please look up MessageDigest in the API documentation, and do a google search for "MD5 java"
    In a networked scenario, there are two issues - firstly the performance in sending copies of files all over the place (imagine if it's a 10Gb file to be compared over a 14.4K modem link, this would take a while). Secondly, the network link itself might insert an error in the file and you'd get a false miss.
    By only sending MD5 digests over the link, you simultaneously reduce the error (shorter files are less likely to be corrupted) and reduce the transmission time (16 bytes takes practically no time to transmit over damp string, let alone any sort of sensible device).
    D.

  • How to compare two files char by char

    Hi,
    I want to compare two files and after Comparison i want all the differences in the new file has to be updated to old file (Without deleteing the contents of the file)?
    Any help will be appriciated.
    Thanks.

    I think i have to elaborate my question�.. for
    example take a file called xyz.xml which contain some
    data which I don�t want to get deleted� after some
    days this file has been modified (i.e. some more data
    has been added) . Now without overwriting the file
    /deleting the earlier contents of file xyz.xml. How
    do I update xyz.xml file?
    Now I think iam clear.
    Thanks.This does not make sense at all! Either your file has been changed or it has not. If it has been changed then there is nothing to do. If it has not been changed then there is nothing to do.

  • How to Compare two Dates in java

    How to Compare two Date Field after getting the values from jTextField1.getText() and jTextField2.getText().

    Date d1=DateFormat.getDateInstance().parse(yourstring1);
    same for d2
    d1.compareTo(d2);
    could be that i misrememberd the exact naems of some functions or mixed up something in the equence of d1=

  • How to compare two files?

    Folks:
    Is there any utility class or method that I can use to compare the contents of two files? Something like diff comamnd in UNIX.
    Thanks a lot!

    I wrote the following program and it seems to work. Any suggestion is welcome!
    import java.io.*;
    public class ContentComparator
    * Returns <code>true</code> if both input streams byte contents is identical.
    * @param input1
    * first input to contents compare
    * @param input2
    * second input to contents compare
    * @return <code>true</code> if content is equal
    boolean contentsEqual( InputStream is1, InputStream is2, boolean ignoreWhitespace )
    try
    if( is1 == is2 )
    return true;
    if( is1 == null && is2 == null ) // no byte contents
    return true;
    if( is1 == null || is2 == null ) // only one has
    // contents
    return false;
    while( true )
    int c1 = is1.read();
    while( ignoreWhitespace && isWhitespace( c1 ) )
    c1 = is1.read();
    int c2 = is2.read();
    while( ignoreWhitespace && isWhitespace( c2 ) )
    c2 = is2.read();
    if( c1 == -1 && c2 == -1 )
    return true;
    if( c1 != c2 )
    break;
    catch( IOException ex )
    finally
    try
    try
    if( is1 != null )
    is1.close();
    finally
    if( is2 != null )
    is2.close();
    catch( IOException e )
    // Ignore
    return false;
    private boolean isWhitespace( int c )
    if( c == -1 )
    return false;
    return Character.isWhitespace( ( char )c );
    public static void main( String[] args )
    InputStream is1 = null;
    InputStream is2 = null;
    try
    is1 = new FileInputStream( "c:\\file1.txt" );
    is2 = new FileInputStream( "c:\\file2.txt" );
    catch( FileNotFoundException e )
    e.printStackTrace();
    ContentComparator cc = new ContentComparator();
    boolean ifIgnoreWhiteSpace = true;
    boolean ifEqual = cc.contentsEqual( is1, is2, ifIgnoreWhiteSpace );
    System.out.println( "Are those two files equal? " + ifEqual );

  • How to compare two files in SAP

    Hi All,
    I have downloaded the contents of a custom table in two files and saved in the uncoverted format, now I want to comapre the contents of these files and see if there is any difference in these files or not. So is there any utility in SAP which I can use to compare these two files.
    Thanks,
    Rajeev

    I can think of 3 alternatives -
    1. Write a report to upload the data and then compare the internal table.
    2. Download data in XLS file and use Excel utilities to compare.
    3. Use file compring tools .( Thanks to Thomas - http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools)

  • How to compare two Timestamps in java ??

    Hi , I have a class CurrentAddress, which is supposed to compare two TimeStamps of two address and store the current address
    I am not able to compare it using the < operator .How am I supposed to compare them ?
    Here is my code . Please reply
    public class CurrentAddress {
         private int EmpID;
         String CurrentEmpAddress;
         Timestamp CurrentTimeStamp;
         boolean TimeIsStampAlreadySet;
         public boolean compareTimeStamps(EmployeeAddress e)
               if(TimeIsStampAlreadySet)
                    Timestamp EmployeesTimeStamp=e.getTimeStamp();
                    if(EmployeesTimeStamp<this.CurrentTimeStamp)--------Compiler flags me here
    }I dont know what method will compare them .Is there anybody who can answer my question?
    Thanks a bunch
    Kavita Rivera

    Hi , Thank you , I will try that .
    I appreciate you writing back .
    Kavita Rivera .

  • How to compare two file differnces

    Hi All ,
    I have two files on my presentation server one file will have some errors and another will conatine corrected , Now I have to compare those two files and display the differed recoreds as a list.Please provide me the required code.
    Thank you ,
    Satheesh.

    Somebody has thought of this before...
    http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools
    You don't need a new ABAP program for this.
    Thomas

  • How to compare two html files

    Hi,
    I have two similar css files and want to have a third version with some properties from one and some from other file. But I do not know how to compare two files in DW. Is there some hint or program?
    Thanks.
    reagrds, Natasa

    hans-g. wrote:
    It might sound strange, but for this I use a word processing program. I build a table with three columns (in portrait or in landscape mode depending on your needs). I set the paragraph marks so that I can compare the paragraphs. The new combinated version I copy into the third column. And then the way is free to copy the new compounded text into your new DW file.
    Hans,
    Have you tried WinDiff, WinMerge, Beyond Compare (my choice) or Compare It! or several others which automate much of the manual system outlined above?
    http://www.scootersoftware.com/moreinfo.php?zz=screenshot&shot=TextCompare
    http://www.scootersoftware.com/moreinfo.php?zz=screenshot&shot=TextMerge
    These diff tools can then be used in conjunction with DW.
    http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7edda .html
    Just a thought.

  • How to open acrobat in java and compare two files using javacode

    I am absolutely new to use acrobat software in Java. I want to open two pdf files at a time and then compare the differences between them thru java program .
    i am not sure how to do it. iam trying many ways without success.
    I used jre and could open open files using runtime method , but couldn't do comaparision. i..e could't access tools menu (alt+t) Compare two files and <enter>. help in java will be appreciated.
    Pls guide me the steps to use the acrobat library. At http://partners.adobe.com/asn/acrobat i found supporting vb and vc only.
    Any help or links are greatly appreciated.

    iText is an open source PDF library, reads a PDF one page at a time. You could check it out. I've used it for writing/splitting/concatenating PDFs, but not comparing files
    http://www.lowagie.com/iText/
    Scott
    http://www.swiftradius.com

  • How to compare two PDF files through PLSQL

    Hi,
    Can any body help that how to compare two PDF files through PLSQL programing and gives the differences as output.
    Thanks,

    Or simply apply an oracle text index on your pdf column:
    SQL>  create table t (id integer primary key, bl blob)
    Table created.
    SQL>  declare
    bf bfile := bfilename('TEMP','b32001.pdf');
    bl blob;
    begin
    dbms_lob.createtemporary(bl,true);
    dbms_lob.open(bf,dbms_lob.lob_readonly);
    DBMS_LOB.LOADFROMFILE(bl, bf,dbms_lob.getlength(bf));
    insert into t values (1,bl);
    commit;
    dbms_lob.close(bf);
    dbms_lob.freetemporary(bl);
    end;
    PL/SQL procedure successfully completed.
    SQL>  create index t_idx on t (bl) indextype is ctxsys.context parameters ('filter ctxsys.auto_filter')
    Index created.
    SQL>  declare
       mklob   clob;
    begin
       ctx_doc.filter ('t_idx', '1', mklob, true);
       dbms_output.put_line (substr (mklob, 1, 250));
       dbms_lob.freetemporary (mklob);
    end;
    Oracle® Database
    Release Notes
    11
    g
    Release 1 (11.1) for Linux
    B32001-04
    November 2007
    This document contains important information that was not included in the
    platform-specific or product-specific documentation
    PL/SQL procedure successfully completed.This generates a text only version of your pdf and standard text comparison methods can be applied ....

  • How to compare two rows in PL/SQL?

    Hi All,
    How to compare two rows in PL/SQL? Is there any method that I can use instead of comparing them column by column?
    Any feedback would be highly appreciated.

    PhoenixBai wrote:
    Hi All,
    How to compare two rows in PL/SQL? Is there any method that I can use instead of comparing them column by column?What "rows" are you referring to?
    If you're talking of rows within a PL/SQL associative array there are techniques as described in the documentation... e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    type v1 is table of number;
      3    r1 v1 := v1(1,2,4);
      4    r2 v1 := v1(1,2,3);
      5  begin
      6    if r1 MULTISET EXCEPT DISTINCT r2 = v1() then
      7      dbms_output.put_line('Same');
      8    else
      9      dbms_output.put_line('Different');
    10    end if;
    11* end;
    SQL> /
    Different
    PL/SQL procedure successfully completed.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    type v1 is table of number;
      3    r1 v1 := v1(1,2,3);
      4    r2 v1 := v1(1,2,3);
      5  begin
      6    if r1 MULTISET EXCEPT DISTINCT r2 = v1() then
      7      dbms_output.put_line('Same');
      8    else
      9      dbms_output.put_line('Different');
    10    end if;
    11* end;
    SQL> /
    Same
    PL/SQL procedure successfully completed.
    SQL>If you're talking about rows on a table then you can use the MINUS set operator to find the rows that differ between two sets of data...
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
    14 rows selected.
    SQL> select * from emp2;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
    7 rows selected.
    SQL> select * from emp
      2  minus
      3  select * from emp2;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
    7 rows selected.If you actually need to know what columns data is different on "non-matching" rows (based on your primary key) then you'll have to compare column by column.

  • Linux Diff tool as External tool in Jdev to compare two files

    Hi, I was looking for adding any diff tool to compare two files in Jdev. I added the usual Linux "diff <file1> <file2>" to compare two files. The way I have provided arguments compares a file against itself.
    Program: diff
    Arguments: ${file.name} ${file.name}
    Directory: ${file.dir}
    My requirement to to right click on the two files which I want to compare and the open them in any diff tool.
    Any ideas?
    Regards,
    Ramesh

    Which jdev version?
    I don't see how this can be done. How do you select two files in jdev?
    As you provided the same name as file1 and file2 it's clear that you compare the file to itself.
    Timo

  • How to compare two xml schemas

    Hello guys,
    How to compare two xml schemas? is there any tool for that?
    Thanksinadvance
    kavita//

    XML Files may be compared with the oracle.xml.differ.XMLDiff class.
    A file consisting of the differences in the xml files gets generated. An XSLT to convert one file to the other also gets generated.

Maybe you are looking for

  • Problem compling JSP with struts tags on Weblogic 8.1

    I have deployed a web application in Weblogic 8.1. However, I am facing a problem while the JSPs are getting compiled. The JSPs ahve taglib declarations referring to Struts tag library files that are present in WEB-INF folder. Stacktrace: C:\java\bea

  • Multiple EDI Connections from ECC

    Hello All, Could you please let me know is it possible to create 2 ALE connections in 1 system and then choose as per partner profile which connection to be assigned? Regards, Anand

  • Deactivating Font Book

    I got so fed up of Font Book I download another Font Management software. What I'd like to know is will Font Book still be running in the background as well as the new font software? One of the reasons why I was using Font Book was to deactivate all

  • FlashPro CS6 BUG - selecting items in library with textfields - fixed in latest 5.5.1, back in CS6!

    This bug was removed from updated CS5.5, and it is back in it's extreme annoyance in CS6. Whenever I select in the library a symbol, which contains textfields who's font is set to a custom font (i.e., Text-Project, linked to Verdana), for EACH of the

  • Imessage just stopped working today...

    My imessage was working fine until today (installed ios7 weeks ago).  It now stalles out on sending messages.  I tried to turn imessage off and on.  I tried to reset the network as other have stated, but my iphone 5 still will not work with imessage.