【发布时间】:2016-09-20 01:48:47
【问题描述】:
我正在尝试将文本文件(输入和输出文件)作为try-catch 块内的命令行参数传递。
这是一个sn-p的代码:
try {
PrintWriter outFile = new PrintWriter(new FileOutputStream(args[0]));
} catch (FileNotFoundException exc) {
System.out.println("file does not exist");
} catch (Exception e) {
System.out.println("general exception");
}
我试图通过传递一个不存在但它似乎不起作用的文件来检查它,即使在一般例外情况下也是如此。我也尝试了printStream,但没有真正改变。
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
根据FileOutputStream JavaDoc,
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.也许你传入的文件CAN被创建了,所以它正在为你创建它。也许让目录只读,看看它是否仍然有效。
标签: java eclipse command-line-arguments