I am trying to read in a file that holds an unknown number of x and y coordinates that are to be later plotted into a 2-D array. Does the file have to be read through twice? Once to determine size of the array needed to plot all coordinates, then a second time to actually plot them, or can this all be done in one step?
import java.io.*;
import java.util.Scanner;
public class patternRec {
public static void main (String[] args){
String FileName = "data.dat";
readFile(FileName);
}
public static void readFile(String f){
int x=0,y=0;
try{
Scanner input = new Scanner(new File(f));
while(input.hasNextInt())
{
x = input.nextInt();
y = input.nextInt();
System.out.println("x: " + x + " y: " +y);
if(x != 33)
{
inputStroke(x,y);
}
}
}catch(Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void inputStroke(int x_val,int y_val){
array[x_val][y_val] = 1;
}
public static void printStroke(int [][]array){
for(int i = 0; i< arraysize; i++){
for(int j=0;j< arraysize; j++){
if(array[i][j] == 1)
System.out.print("*");
else
System.out.print(" ");
}System.out.println();
}
}
}