• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read data from a text file that contains headings into an arraylist  RSS feed

 
Thomas Molloy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all. Quick question (sorry if my title was a bit hard to understand).

I have a text file containing data I want read into an array list, which is a fairly simple task by itself. However, the text file contains titles (or fields, not sure what they're called) in among the data I require. For example: "Brand: Peter". The word Peter is what I need. I have thought about adding commas between the information and the next title (like Brand: Peter, ....) and having the data between the semicolon and the comma read, but that won't work as I also have a price field with the numbers separated by commas.

Is there another way I can approach this? Again, sorry for my bad explanation.   

Cheers
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It almost sounds like you have some control over the way that text file is structured. Do you?  If you do, then consider that there are purpose-built separator characters.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if the file need to be pure text, you can use the tab character, or pick a character that is unlikely to be used, like the pipe character (|).
 
Thomas Molloy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junilu and Knute. Thanks for the quick reply. I forgot to mention that the text file is also created from an array, sorry. I would lose the headings all together, but the data on it's own would be a bit hard to understand. I will look into the separators you both mentioned (never though of the tab). The purpose of this post was to just make sure I wasn't doing it the hard way.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lookup CSV file or comma separated values.  Despite the name, you can use any character as a separator.
 
Carey Brown
Saloon Keeper
Posts: 3327
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CSV is the typical way to handle your kind of data, in which case, the first line is usually the column names separated with your delimiter of choice, and the subsequent lines don't have any headers at all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!