Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Delete a File 
 

In this section, you will learn how a specified file or directory is deleted. For deleting a file from a directory you need to give the file name to be deleted.

 

Delete a File 

                         

In this section, you will learn how a specified file or directory is deleted. For deleting a file from a directory you need to give the file name to be deleted.

Description of program:

The following code of program deletes a file from a directory. In this program the compiler will ask to enter the name of the file to be deleted. For this we have used "BufferedReader(new InputStreamReader(System.in));" method as you very well know about it. If the file exists in the directory then it will be deleted otherwise we will get a message that "file was not successfully deleted".

import java.io.File;
import java.io.*;

public class DeletingFile {
  public static void main(String args[])throws IOException{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter the file name to delete:");
    String file_name = in.readLine();
    File file = new File("File already exist!");
    boolean exist = file.createNewFile();
     if (!exist){
     System.out.println("File was successfully deleted.\n");
     else {
     System.out.println("File was not successfully deleted.\n");
     }
   }
}
        

Output of the program:

C:\unique>javac DeletingFile.java

C:\unique>java DeletingFile
Enter the file name to delete:wonderful.txt
File was successfully deleted.

C:\unique>

Download this example.

                         

» View all related tutorials
Related Tags: c orm form time script object io objects help method sed system ip collection this opera create show for work

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

The above code is totally wrong, so correct it!!!

Posted by Vipin Paliwal on Wednesday, 09.10.08 @ 13:50pm | #78494

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.