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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:32:21+00:00 2026-05-15T19:32:21+00:00

I want map my object from text file, the text file contents are like

  • 0

I want map my object from text file, the text file contents are like this :

~
attribute1value
attribute2value
attribute3value
attribute4value
attribute5value
attribute6value
~
attribute1value
attribute2value
attribute3value
attribute4value
attribute5value
attribute6value
...continued same 

So for each 5 attributes I want to create new object and map those 6 properties to it(that is not issue), the issue is how can I distinguish lines while reading, how can I get the first group, second group etc . thank 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-05-15T19:32:22+00:00Added an answer on May 15, 2026 at 7:32 pm

    Here is a more flexible approach. We can specify a custom (single-line) delimiter, no delimiter is actually needed at the beginning or at the end of the file (but can be given), the number of lines of a record is flexible. The data is parsed into a simple model which can be used to validate data and create the final objects.

    private String recordDelimiter = "~";
    
    public static List<List<String>> parse(Reader reader) {
    
       List<List<String>> result = new ArrayList<List<String>>();
       List<String> record = new ArrayList<String>();
       boolean isFirstLine = true;
    
       while ((line = reader.readLine()) != null) {
    
          line = line.trim();
    
          if (line.length() == 0) {
            continue;  // we skip empty lines
          }
    
          if (delimiter.equals(line.trim()) {
            if (!isFirstLine) {
              result.add(record);
              record = new ArrayList<String>();
            } else {
              isFirstLine = false;   // we ignore a delimiter in the first line.
            }
            continue;
          } 
    
          record.add(line);
          isFirstLine = false;
       }
    
       if (!result.contains(record))
         result.add(record);   // in case the last line is not a separator
    
       return result;
    
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create an object, starting from something like: var map = {};
I want to map a INI file as a python object. So if the
I have this object graph, I want to map: abstract Account (username, password, ...)
I want to create a Map object that can lose value only if we
I have one very general object that I want to map to a destination
I haev an object with a DateTime property. I want to map the time
I have a map that represents a DB object. I want to get 'well
I'm using Richfaces JSF and I want to iterate over an Map<Object,Object> . I
I have a Map, that I want to persist. The domain object is something
I am reading in a String from a text file which contains a date

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.