我是设置了一个Button button_char按钮,点击按钮之后的操作
例如:读取很多姓名和号码的.txt文件,然后分别存入两个数组中,求代码!!
------解决思路----------------------
用list吧,数组你提前知道多大吗?不然会越界的!
FileReader fr = null;
BufferedReader br = null;
List<String> nameList = new ArrayList<String>();
List<String> phoneList = new ArrayList<String>();
try {
fr = new FileReader(new File("H:\\test.txt"));
br = new BufferedReader(fr);
String line = null;
String[] strs = null;
while ((line = br.readLine()) != null) {
strs = line.split("\\s+");
nameList.add(strs[0]);
phoneList.add(strs[1]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}