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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:03:22+00:00 2026-06-03T20:03:22+00:00

I have a text file which is read in. It has delimeters which are

  • 0

I have a text file which is read in. It has delimeters which are <.> . There is a main subject then there are three paragraphs. Lets say title, section1, section2, section3, and then the next article.

How can I store the data so that ArrayList one will have all the titles, ArrayList 2 will have all the section1 information, etc.? I want be able to output these arrays.

E.g.:
Large storm on its way.

about the large storm

statics on storms

conclusions about storms

The example above shows what one record would look like.

public void read()
{
    try
    {
        FileReader fr = new FileReader(file_path);
        BufferedReader br = new BufferedReader(fr);
        String s = "";
        // keep going untill there is no input left and then exit         
        while((s = br.readLine()) != null)
        { }
        fr.close();
    }
    catch (Exception e)
    {
        System.err.println("Error: read() " + e.getMessage());
    }
}

public static void main(String [] args)
{
    Reader reader = new ResultsReader("C:/data.txt");
    reader.read();
    String output = ((ResultsReader)reader).getInput();
    String str = "title<.>section1<.>section2<.>";
    String data[] = str.split("<.>");   
}

I am not sure how to store the data in separate ArrayLists so that they can be traversed.

  • 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-03T20:03:23+00:00Added an answer on June 3, 2026 at 8:03 pm

    You cannot create arrays and put the data into them, because you don’t know how large to create the arrays. So, use a list instead and then turn them into arrays after you have finished reading the file:

    List tilesList = new ArrayList<String>();
    // etc.
    
    FileReader fr = new FileReader(file_path);
    BufferedReader br = new BufferedReader(fr);
    String s = null // I think this should be null, so that if there are no lines, 
                    // you don't have problems with str.split();
    while((s = br.readLine()) != null) {
      String[] line = str.split("<.>");
      tilesList.add(line[1]);
      // etc.
    }
    fr.close();
    
    String[] tiles = tilesList.toArray(new String[tilesList.size()]);
    // etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have one text file which has the following text "\u5b89\u5fbd\u5b5f\u5143" When we read
I have a file which contains several text entries, say one two three Now,
I have to read a text file which is Unicode with UTF-8 encoding and
I have a word file () which has many text fields and a startup
I have a text file which has the following data {i:1, j:2} {k:3, l:10}
I have a text file which has first line as below: j0W82LBrSdUbw Basically it
So I am reading from a text file which has product information I have
I want to read a text file which has text as follows(sample) abc ip-32-56-198-18.com
I have a text file (c:\input.txt) which has: 2.0 4.0 8.0 16.0 32.0 64.0
If i have a project which has a text file inside of it and

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.