TXT文本中如据形如:
-2,2
-1,3
0,1
1,9
2,8读入二维数组效果为:
temp[0][]={-2,-1, 0, 1, 2};
temp[1][]={ 2, 3,1,9,8}; 新手
请大家指点
-2,2
-1,3
0,1
1,9
2,8读入二维数组效果为:
temp[0][]={-2,-1, 0, 1, 2};
temp[1][]={ 2, 3,1,9,8}; 新手
请大家指点
ArrayList<String> temp1=new ArrayList<String>();
ArrayList<String> temp2=new ArrayList<String>();
try{
FileInputStream fstream = new FileInputStream("textfile.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
if (strLine.split(",").length==2){
temp1.add(strLine.split(",")[0]);
temp2.add(strLine.split(",")[1]);
}
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
String temp[][] = new String[2][];
temp[0] = (String[]) temp1.toArray();
temp[1] = (String[]) temp2.toArray();
}
流用的有点乱,既然用Reader了,就不要用DataInputStream了。
in.close();->br.close();