|
-
Passing parameters to the "main" method
I have a basic program that deletes a file. The problem I'm having is passing
the file name to the class. I've tried putting the file in the same directory
as the program, adding the full path to the file and putting it in the root
directory but neither worked. The class is able to read in the file name
but when it gets to the Delete method an exception is thrown when it tries
to create a new file object. I assume I'm not passing the parameter correctly.
Any help would be greatly appreciated.
Regards
Andrew
import java.io.*;
public class Delete {
public static void main(String[] args){
if(args.length != 1){
System.err.print("Usage: java Delete <file or directory>");
System.exit(0);
}
try{ Delete(args[0]); }
catch(IllegalArgumentException e){
System.err.print(e.getMessage());
}
}//end main
public static void Delete(String filename){
//create a file object to represent the file name
File f = new File(filename); /**ERROR HERE**/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks