Input Stream as an Object?
I am reading in a file using:
Code:
JFileChooser fileopen = new JFileChooser();
String Title = "Please select your matrix file";
fileopen.setDialogTitle(Title);
int ret = fileopen.showDialog(null, "Open file");
if (ret == JFileChooser.APPROVE_OPTION) {
file = fileopen.getSelectedFile();
}
try {
FileInputStream fstream = new FileInputStream(file);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str;
//Iterate over each line in the file and get a count on the number of Rows. This will help determine the
//size of the LinkedListArray.
while ((str = in.readLine()) != null) {
Lines++;
}
in.close();
//We have to account for the matrix dimensions row, so remove a row.
RowCount = Lines - 1;
} catch (Exception e) {
System.out.println(e.toString());
System.exit(1);
}
This is to get the number of rows in the file so I can initialize a LinkedListArray to its proper size. Later in my program, I create a new file input stream and read in lines from the same file again to actually do the processing. Is there a way that I can gather thee data from the file during the first process, and store it, so that the 2nd time I dont have to read the file again.