FileReader / Buffered Reader
Hi there, I have a simple problem you might can help me.. I used FileReader and BufferedReader in order to read data from my pc. My data is a representation of numbers separated by commas. Eg.
0,1,2,3,4,5
3,2,2,3,4,5
6,1,2,3,4,5
.
.
.
So i did the following function in order to exclude the commas and insert my data into arrays to help me to manipulate the data. :
Code:
public class LoadData {
DataTool DT = new DataTool();
String[] Networktemp = null;
int a;
int b;
int count=0;
int dimensionscount=0;
int classescount=0;
Vector<Integer> classes = new Vector<Integer>();
Vector<Integer> dimensions = new Vector<Integer>();
public void Loaddata() {
try {
File DataFile =DataTool.menu.getSelectedFile();
FileReader file = new FileReader(DataFile);
BufferedReader buff = new BufferedReader(file);
boolean eof = false;
dimensionscount=0;
classescount=0;
while (!eof){
String lineNetwork = buff.readLine();
//System.out.println(" lineNetowork :" +lineNetwork.substring(2));
System.out.println("Classes count: " +classescount);
if (lineNetwork ==null)
eof = true;
else {
Networktemp = lineNetwork.split(",");
classes.addElement(Integer.parseInt(Networktemp[0]));
for (int i=1; i<Networktemp.length; i++){
dimensionscount++;
dimensions.addElement(Integer.parseInt(Networktemp[i]));
}
classescount++;
// System.out.println(" Classes Vector: " +classes);
// System.out.println(" Dimensions: " +dimensions);
}
}
count = (dimensionscount/classescount);
int[][] DataArray = new int[classescount][count+1];
for (int i=0; i<classescount; i++){
a = classes.elementAt(i);
DataArray[i][0] = a;
}
for (int q=0; q<count; q++){
for (int z=0; z<classescount; z++){
b = dimensions.elementAt(z*5+q);
DataArray[z][q+1] = b;
System.out.println(" this is dimensions: " +b);
}
}
buff.close();
//===========================================================================================
// Print Array
//===========================================================================================
for (int i=0; i<DataArray.length; i++){
for (int j=0; j<DataArray[i].length; j++) {
System.out.print(" " + DataArray[i][j]);
}
System.out.println(" ");
}
} catch (IOException e){
System.out.println(" Errror....." +e.toString());
}
}
My problem is .. at the moment i want to use data that in the third line there is a line white space and then it continues normally. Once it starts reading the data and reaches the third line then it crashes because of the condition Code:
if (lineNetwork ==null)
which is used to stop the program until there is no more rows in the txt file.
So, is there any way that I could "bypass" the first three lines and start from the 4th and start reading the data (i ve tried to use substring on my read line but did not work) any ideas
Thank you