I want to read a file in Java and put the numbers from the file into the (x,y) coordinates of a Point2D[] array. How would I go about doing this?
my file looks like:
5 4
6 2
4 1
which are points (5,4) (6,2) (4,1).
I want to read a file in Java and put the numbers from the file into the (x,y) coordinates of a Point2D[] array. How would I go about doing this?
my file looks like:
5 4
6 2
4 1
which are points (5,4) (6,2) (4,1).
Say you have a
Pointclass that looks like something like this (you could also use thejava.awt.geom.Point2Dclass but it is not advisable apparently) :And a file called
points.txtthat you want to parse with the following contents:You could use a
BufferedReaderto read the file line by line:Output: