Java代入のファイル操作の例外処理用のサンプルプログラムを作成することになっています。私はC++の人なので、理解するのに苦労しています。誰かが以下の私のコードの欠陥を指摘することができれば、それは本当に非常に役に立ちます。この記事を参照しています。Eclipseは、「FileNotFoundExceptionの到達不能なcatchブロック。この例外は、tryステートメントの本体からスローされることはありません」というエラーを表示します。
import java.io.*;
public class file {
public static void main(String[] args) {
String arg1 = args[0];
String arg2 = args[1];
System.out.println(arg1);
System.out.println(arg2);
File f1, f2;
try {
f2 = new File(arg2);
f1 = new File(arg1);
}
catch(FileNotFoundException e) {
/*
if(!f1.exists()) {
System.out.println(arg1 + " does not exist!");
System.exit(0);
}
if(!f2.exists()) {
System.out.println(arg2 + " does not exist!");
System.exit(0);
}
if(f1.isDirectory()) {
System.out.println(arg1 + " is a Directory!");
System.exit(0);
}
if(f2.isDirectory()) {
System.out.println(arg2 + " is a Directory!");
System.exit(0);
}
if(!f1.canRead()) {
System.out.println(arg1 + " is not readable!");
System.exit(0);
}
if(!f2.canRead()) {
System.out.println(arg2 + " is not readable!");
System.exit(0);
}*/
}
}
}