have some problem reading a file in java and save each element into 2 arrays. my txt is made like this
2,3
5
4
2
3
1
where the first line is the lenght of two array A=2 and B=3 and then the element of each array. I don't know how to save them into A and B and initialized the array with their lenght. At the end each array will be A=[5,4] B=[2,3,1]
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("prova.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != " ") {
String[] delims = strLine.split(",");
String m = delims[0];
String n = delims[1];
System.out.println("First word: "+m);
System.out.println("First word: "+n);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
this is what i made..i used System.out.println.... just to print in console it's not necessary...Someone can help me, give me some advice? thanks in advance