Last active
August 29, 2015 14:17
-
-
Save javiergamarra/c0f0427771c85e3fc15b to your computer and use it in GitHub Desktop.
Example of reading a file of points with multiple spaces between
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(final String[] args) { | |
final String path = args[0]; | |
try (BufferedReader br = new BufferedReader(new FileReader(path))) { | |
String line = br.readLine(); | |
final int rows = Integer.parseInt(line); | |
final Point[] points = new Point[rows]; | |
for (int i = 0; i < rows; i++) { | |
line = br.readLine(); | |
final String[] values = line.trim().split(" "); | |
if (values.length >= 2) { | |
final int x = Integer.parseInt(values[0]); | |
final int y = Integer.parseInt(values[values.length - 1]); | |
points[i] = new Point(x, y); | |
points[i].draw(); | |
} else { | |
i--; | |
} | |
} | |
} catch (final IOException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mejoras sobre el código anterior: