1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | double data[][] = new double[316][1024]; try { String filePath = "檔案address"; FileReader in = new FileReader(filePath); StreamTokenizer st = new StreamTokenizer(in); for(i=0;i<316;i++) { //判斷整行結束沒 while( st.nextToken() != StreamTokenizer.TT_EOF) { //判斷是否為整數 if(st.ttype == StreamTokenizer.TT_NUMBER) { data[i][j] = (double)st.nval; } j++; if(j==1024) { j=0; break; } } } in.close(); }//try catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } |
Direct link: https://paste.plurk.com/show/1505746