DELETE IN JAVA

Maha

DELETE IN JAVA

Delete a file in Java, use with delete() method.

We can remove the files using with delete () method .


Example:

import java.io.File; 

public class DeleteFile 

{

public static void main(String[] args) 

File myObj = new File("filename.txt"); 

if (myObj.delete()) 

System.out.println("Deleted the file: " + myObj.getName());

else 

{

System.out.println("Deleted the test file.");

}

Output:

Deleted the test file.


Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send