I'm really knew to this programming thing, and need a little help. My objective is to read data from a file like
2 2
0 0 wwdd
0 1 wwxd
1 0 ddwd
1 1 ddww
I have read the file line by line, but I do not know how to store the individual values. The first two numbers represent the length and width of the block. The rest are just coordinates.
Any ideas? The code should be flexible in case the row and columns change.
import java.io.*;
import java.util.*;
class FileRead
{
public static void main(String args[])
{
String record = null;
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("h.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null)
{
String delims =" " ; // DEFINES CHARACTER BEING USED
StringTokenizer st = new StringTokenizer(strLine, delims);
int frow = Integer.parseInt(st.nextToken());
int fcol = Integer.parseInt(st.nextToken());
System.err.println(frow);
System.out.println(strLine);
}
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}