Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:50:07+00:00 2026-06-07T10:50:07+00:00

I have two files Which should contain the same values between Substring 0 and

  • 0

I have two files Which should contain the same values between Substring 0 and 10 though not in order. I have Managed to Outprint the values in each file but I need to Know how to Report say id the Value is in the first File and Notin the second file and vice versa. The files are in these formats.

6436346346....Other details
9348734873....Other details
9349839829....Other details

second file

8484545487....Other details
9348734873....Other details
9349839829....Other details

The first record in the first file does not appear in the second file and the first record in the second file does not appear in the first file. I need to be able to report this mismatch in this format:

Record 6436346346 is in the firstfile and not in the secondfile.
Record 8484545487 is in the secondfile and not in the firstfile.

Here is the code I currently have that gives me the required Output from the two files to compare.

package compare.numbers;

import java.io.*;

/**
 *
 * @author implvcb
 */
 public class CompareNumbers {

/**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
    // TODO code application logic here
    File f = new File("C:/Analysis/");
    String line;
    String line1;
    try {
        String firstfile = "C:/Analysis/RL001.TXT";
        FileInputStream fs = new FileInputStream(firstfile);
        BufferedReader br = new BufferedReader(new InputStreamReader(fs));
        while ((line = br.readLine()) != null) {
            String account = line.substring(0, 10);
             System.out.println(account);


        }
        String secondfile = "C:/Analysis/RL003.TXT";
        FileInputStream fs1 = new FileInputStream(secondfile);
        BufferedReader br1 = new BufferedReader(new InputStreamReader(fs1));
        while ((line1 = br1.readLine()) != null) {
            String account1 = line1.substring(0, 10);
            System.out.println(account1);
        }

    } catch (Exception e) {
        e.fillInStackTrace();
    }



}
}

Please help on how I can effectively achieve this.
I think I needed to say that am new to java and may not grab the ideas that easily but Am trying.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:50:08+00:00Added an answer on June 7, 2026 at 10:50 am

    Here is the sample code to do that:

     public static void eliminateCommon(String file1, String file2) throws IOException
    {
        List<String> lines1 = readLines(file1);
        List<String> lines2 = readLines(file2);
    
        Iterator<String> linesItr = lines1.iterator();
        while (linesItr.hasNext()) {
            String checkLine = linesItr.next();
            if (lines2.contains(checkLine)) {
                linesItr.remove();
                lines2.remove(checkLine);
            }
        }
    
        //now lines1 will contain string that are not present in lines2
        //now lines2 will contain string that are not present in lines1
        System.out.println(lines1);
        System.out.println(lines2);
    
    }
    
    public static List<String> readLines(String fileName) throws IOException
    {
        List<String> lines = new ArrayList<String>();
        FileInputStream fs = new FileInputStream(fileName);
        BufferedReader br = new BufferedReader(new InputStreamReader(fs));
        String line = null;
        while ((line = br.readLine()) != null) {
            String account = line.substring(0, 10);
            lines.add(account);
        }
        return lines;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files which both contain a list of words. Is there an
I have two files called file_utils.h and file_utils.cpp which contain some methods and variables
I have two ocx files which i registered on my computer using regsvr32. I
I have two batch files which is used to run a large C++ build,
I have two CSV files which use @ to divide each column. The first
I have the following code which will generate two pdf files containing plots to
I have a web application and two class files, First class is MyClass.class which
I have two web forms which are filled in by the user. They contain
I have two files A and B. Both files contain 2 columns, x and
Given two MS SQL databases which are known to have identical schemas, how should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.