这是问题代码:如果我在项目级别导入文本文件,它会给我这个:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at edu.ilstu.ConcertDriver.main(ConcertDriver.java:59)
如果我只将文件导入到源文件夹等较低目录,则会引发 FileNotFoundException。我究竟做错了什么?
我的文件包含以下元素:
栗色 5
15
40
单向
10
50
珍珠果酱
20
30
注意30后返回下一行
String inputFileName = "concerts.txt";
Scanner inputStream = null;
try
{
inputStream = new Scanner(new File(inputFileName));
}
catch(FileNotFoundException e)
{
System.out.println("Error opening the file " + inputFileName);
System.exit(0);
}
String bandName1=null;
int showCapacity1=0;
int ticketPrice1=0;
String bandName2=null;
int showCapacity2=0;
int ticketPrice2=0;
String bandName3=null;
int showCapacity3=0;
int ticketPrice3=0;
bandName1 = inputStream.nextLine();
showCapacity1 = inputStream.nextInt();
ticketPrice1 = inputStream.nextInt();
bandName2 = inputStream.nextLine();
showCapacity2 = inputStream.nextInt();
ticketPrice2 = inputStream.nextInt();
bandName3 = inputStream.nextLine();
showCapacity3 = inputStream.nextInt();
ticketPrice3 = inputStream.nextInt();