Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Reading data to an ArrayList<Point> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading data to an ArrayList<Point>" Watch "Reading data to an ArrayList<Point>" New topic
Author

Reading data to an ArrayList<Point>

Ryan Callen
Greenhorn

Joined: Nov 29, 2012
Posts: 22
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

Joined: Oct 01, 2001
Posts: 2854
    
  11

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading data to an ArrayList<Point>