Scanner read=new Scanner(file);
此语句中出现异常“FileNotFoundException”。
import java.util.*;
import java.io.*;
public class shoppingList {
public static void main(String []args)throws IOException {
File file=new File("MyList.txt");
try {
if(file.exists()==false)
throw new FileNotFoundException("the file input doesn't exist");
}
catch(FileNotFoundException e){System.out.print(e.getMessage());}
//I tried handling the exception but it didn't work
Scanner read=new Scanner(file);
File outfile=new File("MyReceipt.txt");
FileOutputStream fos=new FileOutputStream(outfile);
PrintWriter output=new PrintWriter(fos);
while(read.hasNext()) {
String item=read.next();
double price=read.nextDouble();
String status=read.next();
output.println("My Receipt: ");
output.println("--------------------");
if(status.equals("Done")==true)
output.println(item+" "+price);
double total=0;
total+=price;
output.println("--------------------");
output.println("total= "+total);
}
read.close();
output.close();
}
}