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

  • SEARCH
  • Home
  • 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 7722149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:05:52+00:00 2026-06-01T04:05:52+00:00

I wish to: Reading in two files Split the files into individual strings Compare

  • 0

I wish to:

  1. Reading in two files
  2. Split the files into individual strings
  3. Compare the two string lists and retrieve strings that are unique to a file.

At the moment I am running in to the problem of finding a way to call the two methods used to call in the files (one for each file) to the same method in order to be compared.

Both methods use a try-catch-while statement and if I try to read all of the entries after the while statement only a single is shown and not the entire list.

Is there a way to send parts of both methods as parameter to a single new method?

Here is the code for the program. I know that there are problems with the way that I am doing the program, but I am only doing it the way that I was taught.

  File mainEmails = new File("Testrun.txt");
  Scanner inputScanner = null;


    int counter = 1;
    String fullName = null;
    String position = null;
    String companyName = null;
    String telNumber = null;
    String emailAddress = null;

  try
  {

    inputScanner = new Scanner(mainEmails);

  }

  catch(FileNotFoundException e)
  {
    System.out.println("File has not been found.");
  }

  while (inputScanner.hasNextLine())
  {

    String nextLine = inputScanner.nextLine();
    String [] splitFile = nextLine.split(",");
    for (int i = 0; i <splitFile.length;i++)
    {
      if(i==0)
        {
          fullName = splitFile[0];
        }
        else if(i==1)
        {
          position = splitFile[1];
        }
        else if(i==2)
        {
          companyName = splitFile[2];
        }
        else if(i==3)
        {
          telNumber = splitFile[3];
        }
        else if(i==4)
        {
          emailAddress = splitFile[4];
        }
        else if(splitFile[i] == null)
      {
        System.out.println("You have failed!");
      }
    }
  }


public static void deletionList()
{

  File deletionEmails = new File("Testrun1.txt");
  Scanner inputScanner1 = null;

    String deletionfullName = null;
    String deletionposition = null;
    String deletioncompanyName= null;
    String deletiontelNumber = null;
    String deletionemailAddress = null;

    try
  {
    inputScanner1 = new Scanner(deletionEmails);
  }
    catch(FileNotFoundException e)
  {
    System.out.println("File has not been found.");
  }
   while (inputScanner1.hasNextLine())
  {
    String deletionnextLine = inputScanner1.nextLine();
    String [] deletionsplitFile = deletionnextLine.split(",");
    for (int i = 0; i <deletionsplitFile.length;i++)
    {
      if(i==0)
        {
          deletionfullName = deletionsplitFile[0];
        }
        else if(i==1)
        {
          deletionposition = deletionsplitFile[1];
        }
        else if(i==2)
        {
          deletioncompanyName = deletionsplitFile[2];
        }
        else if(i==3)
        {
          deletiontelNumber = deletionsplitFile[3];
        }
        else if(i==4)
        {
          deletionemailAddress = deletionsplitFile[4];
        }
        else if(deletionsplitFile[i] == null)
      {
        System.out.println("You have failed!");
      }
    }
   }
}

What I am trying to do is to take the fullName, emailAddress from the first split and deletionfullName and deletionemailAddress from the second split and compare the first and second of each, respectively. Each file will have a number of fields in it, and I am only interested in the fullName and emailAddress fields.

  • 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-01T04:05:54+00:00Added an answer on June 1, 2026 at 4:05 am

    It is quite confusing to understand how you are trying to implement your solution, so may I suggest you look at a different way of doing the whole read-and-compare process. For example, I would suggest doing something like this… (in psuedocode)

    public void compareFiles(String file1, String file2){
        // Read the lines of each file into String[] arrays
        String[] file1Lines = readAndSplitIntoLines(file1);
        String[] file2Lines = readAndSplitIntoLines(file2);
    
        // compare the lines
        for (int x=0;x<file1Lines.length;x++){
            for (int y=0;y<file2Lines.length;y++){
                if (file1Lines[x].equals(file2Lines[y])){
                    // match. set it to null
                    file1Lines[x] = null;
                    file2Lines[y] = null;
                    // break out of the inner loop and start comparing the next line
                    break;
                }
            }
    
        // remove the duplicates (which are now null values), creating a smaller array of uniques.
        String[] newFile1 = shrinkArrayByRemovingNulls(file1Lines);
        String[] newFile2 = shrinkArrayByRemovingNulls(file2Lines);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading binary data (either by network stream or from files) that is predefined
I have an xml string that I wish to traverse using LINQ to XML
I wish to read incoming XML files that have no specific name (e.g. date/time
I wish Subversion had a better way of moving tags. The only way that
I wish to know all the pros and cons about using these two methods.
I wish to implement my software on a shareware basis, so that the user
I wish to test a function that will generate lorem ipsum text, but it
I'm reading an excel file with C# and OleDB (12.0). There I have to
I am having trouble granting reverse permissions for apps that I wish to provide
I have a piece of text, that I wish to show truncated, but when

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.