Use createNewFile() and delete() methods
Example
File file = new File("c:\\newfile.txt");
if (file.createNewFile())
System.out.println("File is created!");
else
System.out.println("File already exists.");
if(file.delete())
System.out.println(file.getName() + " is deleted!");
else
System.out.println("Delete operation is failed.");
No comments:
Post a Comment
Note: only a member of this blog may post a comment.