可以通过流的形式读取到所有内容,之后在转换成元素的形式进行实现。举例:
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.*;
public class Test{
public static void main(String[] args) {
Hashtable<String, String[]> dict = new Hashtable<String, String[]>();
try {
BufferedReader reader = new BufferedReader(new FileReader("test.csv"));
String line = null;
while((line=reader.readLine())!=null){
String item[] = line.split(",");
String item2[] = new String[19];
System.arraycopy(item,1,item2,0,19);
dict.put(item[0],item2);
}
Enumeration e2 = dict.keys();
while (e2.hasMoreElements()) {
String key = (String) e2.nextElement();
System.out.println(key);
String[] dd = (String[])dict.get(key);
for (int i=0;i<dd.length;i++) {
System.out.print(dd[i]+" ");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}