Я написал код ниже, но ничего не выходит.У меня есть файл .txt в пакете icecreamcones, но когда я запускаю код, возвращается исключение, и ничего не происходит.
Я изменил исходный файл .dat на .txt.Я попытался переместить его в / src и изменить путь (что я мог сделать неправильно, но все равно не работал в любом случае).
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package icecreamcones;
/**
*
*
*/
public class icecreamCones {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int totalCones = 0;
int totalStrawberry = 0;
String readFile;
try {
TextIO.readFile("icecream.txt");
}
catch (IllegalArgumentException e) {
System.out.println("File not found!");
}
while(!TextIO.eof()){
readFile = TextIO.getln();
totalCones++;
if (readFile.equals("Strawberry")){
totalStrawberry++;
}
}
System.out.println("The total number of sold cones is: " + totalCones);
System.out.println("The total number of sold Strawberry flavoured cones is: "
+ totalStrawberry);
}
}
----------
I need to be able to print out the two statements so I need help figuring out how to make TextIO.readFile work.