这个把一个文本文件读进来,并放到一个数组里面,打印出涞 下面是程序
文本里面就3排数字
4030
2011
2049
import java.io.*;
import java.util.*;
public class test0 {
static int sum = 0;
public static void main(String cgx[]) throws IOException {
String s = "";
try {
readin("readin.txt");
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//sort(x);
}
private static void readin(String path) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(path));
String s = new String();
int x[] = new int[99];
for (int i = 0; i < x.length; i++) {
s = in.readLine();
if (s != null || Integer.parseInt(s) != 0) {
x[i] = Integer.parseInt(s);
System.out.println(x[i]);
}
}
// TODO Auto-generated method stub
}
}这个是错误
4030
2011
2049
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at test0.readin(test0.java:24)
at test0.main(test0.java:9)
Exception in thread "main"