该文件是在我的项目,并正确命名,我很新的JAVA。任何提示,将不胜感激,TIA。在java中找不到文件错误,文件在我的项目文件夹中?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ExceptionsAndCarryOn {
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
Scanner UserInput = new Scanner(new File("Numbers.txt"));
System.out.println("Please enter the numbers: ");
int [] numbers = new int [5];
int i = 0;
while(UserInput.hasNextInt()){
numbers[i++] = UserInput.nextInt();
}
int sum = 0;
for (i = 0; i < numbers.length; i++)
sum += numbers[i];
System.out.println(sum);
UserInput.close();
}
}
你是如何执行的程序? – sidgate
只是在IDE –
和你把文本文件放在哪里? – sidgate