我正在尝试自己学习编程,但仍在尝试掌握它。我收到以下错误:
java.io.IOException:句柄无效
这是我的代码
public class PrimeFinder {
private int[] prime;
FileInputStream input = null;
//default contructor uses the premade file prime.txt that has the first 10000 digits of pi
public PrimeFinder() throws IOException {
try{
input = new FileInputStream ("primes.txt");
}
finally {
if (input != null ) {
input.close();
}
}
}
//constructor with a predefined text file to use.
public PrimeFinder(String txtFile) throws IOException {
try{
input = new FileInputStream(txtFile);
}
finally {
if (input != null ) {
input.close();
}
}
}
public static void main(String[] args) throws IOException{
PrimeFinder tester = new PrimeFinder();
tester.arrayListWithNumbers();
}
}
我相信,每当我调用该arrayListWithNumbers()方法时,都会出现错误,当我尝试显示默认构造函数中的字节数时,它可以很好地工作并显示101281
bytes。