Home Tutorial Java Core Files Java file delete

 
 

Java file delete
Posted on: August 3, 2006 at 12:00 AM
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.

Related Tags for Java file delete:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.