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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:11:35+00:00 2026-05-15T23:11:35+00:00

A file name will be passed in from standard in. I want to open

  • 0

A file name will be passed in from standard in. I want to open it, read it, and create some information based off the text in the file.

For example, if this is a line in the file:

Hristo 3

… then I want to create a Member() named Hristo with a value of 3. So I want to pull out a String for the name and an int for the value. The name and the value are separated by some unknown number of tabs and spaces which I need to ignore. Could I just read the line, use .trim() to get rid of whitespace, and the last character would be the value?

I have not shown the class Member() for simplicity’s sake. This is what I have so far:

public static void main(String[] args) {

    int numMembers = 0;
    ArrayList<Member> veteranMembers = new ArrayList<Member>();

    File file = new File(args[0]);
    FileReader fr;
    BufferedReader br;

    // attempt to open and read file
    try {
        fr = new FileReader(file);
        br = new BufferedReader(fr);

        String line;

        // read file
        while ((line = br.readLine()) != null) {

                // extract name and value from line
                ... ? ...

                // create member
                // initialize name and value
                Member member = new Member();
                veteranMembers.add(member);
        }
        br.close();

    } catch (FileNotFoundException e1) {
        // Unable to find file.
        e1.printStackTrace();
    } catch (IOException e) {
        // Unable to read line.
        e.printStackTrace();
    }
}

How would I parse that line of text?

Thanks in advance for your help.

  • 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-15T23:11:35+00:00Added an answer on May 15, 2026 at 11:11 pm

    I would use the split function.
    You can give it a regular expression as the argument
    i.e.

    line.split(" |\t");
    

    will return array of the words ( {list[0] = Hristo, list[1] = 3} in your example)
    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I write a regex which will replace any file name, with it's
I am having batch file called Formalbuild.bat ,It will take parameter name called componentName.
I like to create a specific filename for a file that will be created
Possible Duplicate: Get file name from URI string in C# How to extract file
Can the save as file name be entered automatically into the save dialog(from a
In an executable Octave script, I want to pass the name of a file
Suppose you are working with some data, which comes from a JSON file. You
I have the following code, which will retrieve a filename from a table and
The file name only coming when saving the exported file, how can we have
I have a file name dayhappy_02_02345.csv How do I get the 02 part out

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.