String fileName = "SDS_DID.txt";
// A File object to represent the filename
File f = new File(fileName);
if (!f.exists) {
JOptionPane.showErrorDialog (null , filename + " is not found.");
}
你不能只在硬盘上的任何地方拿起一个文件,你必须知道它实际上在哪里
# 3 楼答案
System.gc(); // close any streams first
String fileName = "SDS_DID.txt";
// A File object to represent the filename
File f = new File(fileName);
// Make sure the file or directory exists and isn't write protected
if (!f.exists())
throw new IllegalArgumentException(
"Delete: no such file or directory: " + fileName);
if (!f.canWrite())
throw new IllegalArgumentException("Delete: write protected: "
+ fileName);
// Attempt to delete it
boolean success = f.delete();
if (!success)
throw new IllegalArgumentException("Delete: deletion failed");
# 1 楼答案
# 2 楼答案
最常见的问题是找不到文件。 确保文件已经存在
你不能只在硬盘上的任何地方拿起一个文件,你必须知道它实际上在哪里
# 3 楼答案