How do I delete a file?
Category: java.io, viewed: 1333 time(s).
package org.kodejava.sample.java.io; import java.io.File; public class FileDeleteExample { public static void main(String[] args) { // When want to delete a file named readme.txt File file = new File("readme.txt"); // Checks if the file is exists before deletion. if (file.exists()) { System.out.println("Deleting file " + file.getAbsolutePath()); // Use the delete method to delete the given file. file.delete(); } else { System.out.println(file.getAbsolutePath() + " doesn't exists."); } } } |
Can't find what you are looking for? Join our FORUMS and ask some questions!
Related Examples
- How do I store properties as XML file?
- How do I load properties from XML file?
- How do I convert InputStream to String?
- How do I convert string into InputStream?
- How do I get an exception stack trace message?
- How do I use Console class to read user input?
- How do I store objects in file?
- How do I use DataInputStream and DataOutputStream?
- How do I use RandomAccessFile class?
- How do I create a directories recursively?
- How can I get current working directory?
- How can I change a file attribute to writable?
- How can I change a file attribute to read only?
- How do I append data to a text file?
- How do I use LineNumberReader class to read file?
- How do I check for a directory?
- How do I get total space and free space of my disk?
- How do I rename a file or directory?
- How do I check if a file is hidden?
- How do I get the content of a directory?
Most Viewed Examples
Latest Code Examples
Categories
100 Top & Latest
Latest Jobs
Blog Entries
Forums Entries
- Google Chrome
- Re: Importing and scanning the text
- Re: What Java books have you read?
- Re: How to create exe file
- How to create exe file
- Re: What Java books have you read?
- Infix expression
- Importing and scanning the text
- Re: I want to reduce the size of a JPG image
- MOVED: I want to reduce the size of a JPG image
