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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:34:38+00:00 2026-06-04T22:34:38+00:00

I have a long local text file and I would like to write a

  • 0

I have a long local text file and I would like to write a method that will read it and add the first word of each line into an ArrayList of Strings.

I have a very primitive understanding of basic I/O operations. Right now, from what I understand, I would need to have some kind of InputReader object read each first word and then use something like an OutputStreamBuffer to add each of those words as Strings to the ArrayList in turn. Am I on the right track?

If that is correct, I’m not exactly sure what the correct syntax would be to do it (especially with having the InputStreamReader go to the next line after copying the first word in each line. If I’m not even close, what would you guys do?

Thanks a lot for your help everyone. I hope my description was clear enough for you.

  • 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-04T22:34:40+00:00Added an answer on June 4, 2026 at 10:34 pm

    You’re on the right track – here’s my general suggestion for your requirement…

    1. Create an ArrayList<String> for storing your words
    2. Use a BufferedReader to read from your file line-by-line using readLine();
    3. Split the line up and read the first word only (maybe use the String.split() method or a StringTokenizer or a regex expression)
    4. Store the word in the ArrayList using an add() method and then read the next line from point 2.

    There shouldn’t be a need to use an OutputStream for your ArrayList, thats just complicating things.

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

Sidebar

Related Questions

I know how to read/write to local files on iOS using file handles. I
I have written a program in Java to read in a text file of
I have a method that is over 700+ lines long. In the beginning of
I have some long queries (text wise) that I am trying to externalize into
I have long HTTP request ( generating large Excel file - about 60K records
I have long file with the following list: /drivers/isdn/hardware/eicon/message.c//add_b1() /drivers/media/video/saa7134/saa7134-dvb.c//dvb_init() /sound/pci/ac97/ac97_codec.c//snd_ac97_mixer_build() /drivers/s390/char/tape_34xx.c//tape_34xx_unit_check() (PROBLEM)/drivers/video/sis/init301.c//SiS_GetCRT2Data301() /drivers/scsi/sg.c//sg_ioctl()
I have an option to choose between local based data storing (xml file) or
I have a big text file and I am processing it line by line
I have a problem that seems like its a result of a deadlock-situation. Whe
I have a string that contains something like this: ##### abc 'foo' /path/to/filename:1 #####

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.