Click here to Skip to main content
13,792,857 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i have two text files
README.TXT->THIS IS THE PROJECT README FILE.
README1.TXT->THIS IS THE PROJECT README FILE BY KUNAL SHAH.

MY CODE IS:

import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
public class files
{
    // instance variables - replace the example below with your own
    public static void main (String[] args)throws IOException
    {
        Scanner scan,scan1;
        String str,str1,word,word1;
        scan=new Scanner(new File("README.TXT"));
        scan1=new Scanner(new File("README1.TXT"));
        Scanner line,line1;
        ArrayList<string> al1=new ArrayList<string>();
        ArrayList<string> al=new ArrayList<string>();
        while(scan.hasNext())
        {   
            while(scan1.hasNext())
            {
                str1=scan1.nextLine();
                str=scan.nextLine();
                
                line=new Scanner(str);
                line1=new Scanner(str1);
                
                while(line.hasNext())
                {
                    while(line1.hasNext())
                    {
                        word1=line1.next();
                        al1.add(word1);
                    }
                    word=line.next();
                    al.add(word);
                    
                }
            }
        }
    }
}


//reading two text files is accomplished. however i need to compare contents from two files and output that is not common in two files
for my example it should be by kunal shah.

What I have tried:

i have tried to create arraylist<string> and push all tokes from files into two arrayList<string>. however i am not understanding how to output content that is not common in two files.
Posted 10-Nov-17 18:40pm
Updated 10-Nov-17 19:06pm
v4
Comments
PIEBALDconsult 11-Nov-17 0:11am
   
Patrice T 11-Nov-17 0:34am
   
made the direct link
Richard MacCutchan 11-Nov-17 9:00am
   
Iterate through your arrays and find all the matching lines. When you find one you can remove it from both arrays. When you have completed the searches in both arrays what you have left is the data that is not common.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.181207.3 | Last Updated 11 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100