文本文档内容格式如下: 20068456A--张三--班长 20068457B--李四--学委 ...... 存放到数组Object a[][]中 即存放后a[0][0]="20068456A" a[0][1]="张三" a[0][2]="班长" a[1][0]="20068457B" a[1][1]="李四" a[1][2]="学委"
public static void main(String[] args) { //自己修改文件存放路径 String filepath = "e:/test.txt"; String temp = null; Object a[][] = null; BufferedReader br = null; StringTokenizer st = null; int i = 0; try { br = new BufferedReader(new FileReader(filepath)); while (br.ready()) { temp = br.readLine(); if (temp != null && temp != "") { //个人感觉方法split不怎么好用,还是用以下方法比较好 st = new StringTokenizer(temp, "--"); a[i][0] = st.nextToken().trim(); a[i][1] = st.nextToken().trim(); a[i][2] = st.nextToken().trim(); } i++; } } catch (Exception e) { e.printStackTrace(); } finally { try { br.close(); } catch (Exception e) { e.printStackTrace(); } } } 要查看结果的话遍历一下数组a[][]就可以了