TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Deleting the file in Java program
Alagunila Meganathan
Aug 10
2016
Code
589
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
DeleteFile.rar
import
java.io.*;
public
class
DeleteFile{
private
static
void
deletefile(String file){
File f1 =
new
File(file);
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){
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
delete