日期:2014-05-20 浏览次数:20689 次
public static void main(String[] arg) throws Exception{ BufferedReader reader = new BufferedReader(new FileReader("")); List<Integer> values = new ArrayList<Integer>(); while(true){ String line = reader.readLine(); if(line == null){ break; } String[] vStrs = line.split("\\s+"); for(String str : vStrs){ values.add(Integer.valueOf(str)); } } int[] array = new int[values.size()]; int i = 0; for(Integer v : values){ array[i++] = v; } }
------解决方案--------------------
public static void main(String[] arg) throws Exception { BufferedReader reader = new BufferedReader(new FileReader("E:/test.txt")); int[] list = new int[20]; int i = 0; String line = null; while ((line = reader.readLine()) != null) { String[] vStrs = line.split(" "); for (String str : vStrs) { list[i++] = Integer.parseInt(str); } } System.out.println(Arrays.toString(list)); }