Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 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:

Java
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
Updated 10-Nov-17 18: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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900