• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read a text file into a Vector of Points?  RSS feed

 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea how to read the text file into a Vector of Points.I am stuck in the middle of the program by an exception.

I am trying to read coordinates into a Vector of Points , here is the structure of the file.

flower.txt


Java code



best regards,
Omi
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Omi,

think about what you're trying to do here!

You read a line (= String) out of a file and try to put this String in a list of Points ;-) This can't work because the Vector can't know how to convert this String into a Point! You will have to parse each line and create Point objects from the parsed contents.

Marco
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check if this is a way right way to parse them. I am getting the expected result though.



 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see anything wrong with it and it probably wouldn't work if it was wrong I think for this simple problem it's the right solution!

There are advanced ways to parse more complex contents, but this won't be necessary here. If you are interested in this, have a look at "regular expressions".

Marco
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!