FileDocCategorySizeDatePackage
Delete2.javaAPI DocExample915Tue Mar 13 15:32:30 GMT 2001None

Delete2

public class Delete2 extends Object
Delete a file from within Java, with error handling.
author
Ian F. Darwin, ian@darwinsys.com
version
$Id: Delete2.java,v 1.4 2001/03/13 20:32:30 ian Exp $

Fields Summary
Constructors Summary
Methods Summary
public static voiddelete(java.lang.String fileName)

		try {
			// Construct a File object for the file to be deleted.
			File target = new File(fileName);

			if (!target.exists()) {
				System.err.println("File " + fileName + 
					" not present to begin with!");
				return;
			}

			// Quick, now, delete it immediately:
			if (target.delete())
				System.err.println("** Deleted " + fileName + " **");
			else
				System.err.println("Failed to delete " + fileName);
		} catch (SecurityException e) {	
			System.err.println("Unable to delete " + fileName +
				"(" + e.getMessage() + ")");
		}
	
public static voidmain(java.lang.String[] argv)

		for (int i=0; i<argv.length; i++)
			delete(argv[i]);