private static void deletefile(String file) {
int fileName = 500;
int z;
String[] File = new String[fileName];
for (z = 0; z < fileName; z++) {
File f1 = new File(
"C:\\Users\\user\\fypworkspace\\TextRenderer\\abc" + z
+ ".txt");
boolean success = f1.delete();
if (!success) {
System.out.println("Deletion failed.");
System.exit(0);
} else {
System.out.println("File deleted.");
}
}
}
public static void main(String[] args) throws IOException {
switch (args.length) {
case 0:
System.out.println("File has not mentioned.");
System.exit(0);
case 1:
deletefile(args[0]);
System.exit(0);
default:
System.out.println("Multiple files are not allow.");
System.exit(0);
嗨,这是我尝试删除java中的某些文件的代码。它打印出来的文件没有提到过,我试图删除某个文件夹中的一组txt文件。一旦文件丢失,程序应该继续下一个文件。任何人都可以指出我的错误吗?谢谢..删除文件的问题
你的目标是?将abc1.txt,abc2.txt中的所有文件删除到abc500.txt?当一个文件丢失或者您没有写入权限时,程序应该终止还是继续下一个文件? – Nachtfrost 2011-03-10 12:50:12
这里列出什么更容易...您至少已将代码标记为代码。 – Lazarus 2011-03-10 12:55:34
抱歉,我的问题显示不佳,我试图删除某个文件夹中的一组txt文件。一旦文件丢失,程序应该继续下一个文件。请指出我缺乏的地方?谢谢。 – 2011-03-10 13:03:58