Java file delete


 

Java file delete

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

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.

Ads