Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading data to an ArrayList<Point>

 
Ryan Callen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody explain to me the most efficient way to read in data from a text file and organize it into an ArrayList<Point>?

Let's say I have a file called "points.txt" and I need to write a method that will read those values in to my program and organize them into an ArrayList<Point> that I can then return to my main. How would I go about doing that? I understand the basic function of IO, but I seem to be confused with the concept of Points, especially in an ArrayList. Thanks!
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about java.awt.Point or some other class? In any case, the first thing to do is figure out how to read the file a line at a time (assuming the text file is arranged so that the data for one Point appears on one line). Try just printing the lines as you read them at first.

The next thing you have to figure out is how to parse one line into the data you need for a Point, but don't worry about that until you get reading from the file working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic