我正在尝试在自己的时间学习编程,但我仍在努力掌握它。我收到以下错误:
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
.