代码很简洁:
public class ReadIp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = null;
try {
scanner = new Scanner(new File("C:\\Documents and Settings\\Administrator\\桌面\\ip.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
List<String[]> lines = new LinkedList<String[]>();
while (scanner.hasNextLine()) {
lines.add(scanner.nextLine().split("\\s+"));
}
String[][] numbers = lines.toArray(new String[0][0]);
for (int i = 0; i < numbers.length; ++i) {
System.out.println(Arrays.toString(numbers[i]));
}
} }