Java file delete

In this section, you will learn how to delete a file.

 
 

Share on Google+Share on Google+

Java file delete

Ads

In this section, you will learn how to delete a file.

Java file delete

In this section, you will learn how to delete a file.

Description of code

Java makes file manipulation easier by providing many useful tools. Through the use of these tools, you can easily perform file operations. Here we are going to delete a file. For this, we have created an object of File and call the method delete() through the object. This method delete the file from the given path name.

Here is the code:

import java.io.*;

public class FileDelete {
	public static void main(String[] args) {
		File f = new File("C:/newfile.txt");
		f.delete();
	}
}

Through the method delete(), you can delete the file from the given path name.

Advertisements

Posted on: August 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles