import java.io.*;/**
* This class is a static method delete() and a standalone program that
* deletes a specified file or directory.
**/
public class Delete {
/**
* This is the main() method of the standalone program. After checking
* it arguments, it invokes the Delete.delete() method to do the deletion
**/
public static void main(String[] args) {
if (args.length != 1) { // Check command-line arguments
System.err.println("Usage: java Delete <file or directory>");
System.exit(0);
}
// Call delete() and display any error messages it throws.
try { delete(args[0]); }
catch (IllegalArgumentException e) {
System.err.println(e.getMessage());
}
}
/**
* The static method that does the deletion. Invoked by main(), and
* designed for use by other programs as well. It first makes sure that
* the specified file or directory is deleteable before attempting to
* delete it. If there is a problem, it throws an
* IllegalArgumentException.
**/
public static void delete(String filename) {
// Create 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()) fail("Delete: no such file or directory: " +filename);
if (!f.canWrite()) fail("Delete: write protected: " + filename); // If it is a directory, make sure it is empty
if (f.isDirectory()) {
String[] files = f.list();
if (files.length > 0)
fail("Delete: directory not empty: " + filename);
} // If we passed all the tests, then attempt to delete it
boolean success = f.delete();
// And throw an exception if it didn't work for some (unknown) reason.
// For example, because of a bug with Java 1.1.1 on Linux,
// directory deletion always fails
if (!success) fail("Delete: deletion failed");
} /** A convenience method to throw an exception */
protected static void fail(String msg) throws IllegalArgumentException {
throw new IllegalArgumentException(msg);
}
}我在调试这个程序的时候编译可以通过,但是用java命令运行的时候就出现了如题的错误,请各位帮我分析一下哪里的问题呢,我在google里面搜索这个问题的常见原因,多是因为环境变量没有配置好才出现的,但是我其他的程序都是可以正常运行的,只有这个出现了错误,所以我想不应该是环境变量的问题,请各位帮我看一下,谢谢~~~
* This class is a static method delete() and a standalone program that
* deletes a specified file or directory.
**/
public class Delete {
/**
* This is the main() method of the standalone program. After checking
* it arguments, it invokes the Delete.delete() method to do the deletion
**/
public static void main(String[] args) {
if (args.length != 1) { // Check command-line arguments
System.err.println("Usage: java Delete <file or directory>");
System.exit(0);
}
// Call delete() and display any error messages it throws.
try { delete(args[0]); }
catch (IllegalArgumentException e) {
System.err.println(e.getMessage());
}
}
/**
* The static method that does the deletion. Invoked by main(), and
* designed for use by other programs as well. It first makes sure that
* the specified file or directory is deleteable before attempting to
* delete it. If there is a problem, it throws an
* IllegalArgumentException.
**/
public static void delete(String filename) {
// Create 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()) fail("Delete: no such file or directory: " +filename);
if (!f.canWrite()) fail("Delete: write protected: " + filename); // If it is a directory, make sure it is empty
if (f.isDirectory()) {
String[] files = f.list();
if (files.length > 0)
fail("Delete: directory not empty: " + filename);
} // If we passed all the tests, then attempt to delete it
boolean success = f.delete();
// And throw an exception if it didn't work for some (unknown) reason.
// For example, because of a bug with Java 1.1.1 on Linux,
// directory deletion always fails
if (!success) fail("Delete: deletion failed");
} /** A convenience method to throw an exception */
protected static void fail(String msg) throws IllegalArgumentException {
throw new IllegalArgumentException(msg);
}
}我在调试这个程序的时候编译可以通过,但是用java命令运行的时候就出现了如题的错误,请各位帮我分析一下哪里的问题呢,我在google里面搜索这个问题的常见原因,多是因为环境变量没有配置好才出现的,但是我其他的程序都是可以正常运行的,只有这个出现了错误,所以我想不应该是环境变量的问题,请各位帮我看一下,谢谢~~~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货