2 つの個別の例外が必要です。1 つは .pro ファイルが欠落している場合にスローされ、もう 1 つは欠落しているファイルが .cmd の場合にスローされます。現在の設定では、いずれかが欠落している場合に両方の例外がスローされます。ここで何が間違っていますか?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.xml.ws.Holder;
public class Inventory {
static String FileSeparator = System.getProperty("file.separator");
public static void main(String[] args) {
String path = args[0];
String name = args[1];
ArrayList<Holder> because = new ArrayList<Holder>();
try {
File product = new File(path + name + ".pro");
Scanner scan = new Scanner(product);
while (scan.hasNext()) {
System.out.print(scan.next());
}
scan.close();
} catch (FileNotFoundException e) {
System.out.println("Usage: java Inventory <path> <filename>");
System.out.println("The products file \"" + name + ".pro\" does not exist.");
}
try {
File command = new File(path + name + ".cmd");
Scanner scan = new Scanner(command);
while (scan.hasNext()) {
System.out.println(scan.next());
}
} catch (FileNotFoundException f) {
System.out.println("Usage: java Inventory <path> <filename>");
System.out.println("The commands file \"" + name + ".cmd\" does not exist.");
}
}
}