回覆列表
  • 1 # 孟海濤19800208

    可以透過流的形式讀取到所有內容,之後在轉換成元素的形式進行實現。舉例:

    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]+"\t");

    }

    System.out.println();

    }

    }

    catch (Exception e) {

    e.printStackTrace();

    }

    }

    }

  • 中秋節和大豐收的關聯?
  • 有哪些文學書籍或小說推薦?