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 5949115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:12:13+00:00 2026-05-22T17:12:13+00:00

I have a textfile containing users’ information, in row form separated with commas. I’ve

  • 0

I have a textfile containing users’ information, in row form separated with commas. I’ve used a combination of experimenting and research to try and separate each row into individual pieces of information (by using the split function) which can be stored in the array, and then searched against. With the code I have each name and username in the textfile gets repeated 4 times each, how I don’t understand. All i’ve managed to do is confuse myself further, but all I need is to pull each row from the textfile, split it into its 4 separate pieces of information and store them in memory in some way to search against. The code i have is;

package assignment;


import java.io.*;

public class readUser {
public void read()
{
    try{

        FileInputStream propertyFile = new FileInputStream("AddUser.txt");

        DataInputStream input = new DataInputStream(propertyFile);
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));

        String line;

        while ((line = reader.readLine()) != null) {

            String[] items = line.split(",");
            String[][] usersArray = new String [5][2];
            int i;
            for (String item : items) {

                for (i = 0; i<items.length; i++){
                    if (i == 0) {
                        System.out.println("Name: " + items[i]);
                    } else if (i == 1) {
                        System.out.println("Username: " + items[i]);


                }
            }
            }
            //System.out.println(line);



        }
        input.close();
    }
    catch (Exception e){

        System.err.println("Error: " + e.getMessage());
    }
        }

}

Thanks for any advice on this

  • 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-05-22T17:12:14+00:00Added an answer on May 22, 2026 at 5:12 pm

    Take a look at the break-down of your code and the problem becomes clear:

    for each line in property file (while loop):
        for each item in line:
            for each item in line:
               if item 0 print username
               else if item 1 print username
               endif
            end loop
         end loop
    end loop
    

    Your code is basically iterating over the list of items twice. Keep in mind that in Java the following two code snippets are equivalent — in that they both iterate over the values of an array or collection.

    A

    for (String item : items) {...}
    

    B

    for (int i = 0; i < items.length; i++) {
        String item = items[i];
        ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file containing ~300k rows. Each row has a varying number
I have text file, names.txt, with every row containing a last name: Smith Johnson
Okay, so I have this utf-8 textfile containing 20 tab-seperated columns of various types
I have a text file containing data/fields which are separated by exact column no.
I have a text file containing the row numbers of the rows that should
i have a textfile containing these kind of words PEOPLE John 0218753458 ENTERPRISE stock
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a text file containing unwanted null characters (ASCII NUL, \0 ). When
I have a text file containing a number of records. Each record is stored
I have a text file (txt) containing formatted text (just line breaks, carriage returns

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.