File Deletion
File Deletion
Deleting files is easy in java, just write an if…..else block and use the delete() method inside it.
Example:
Output:
Deleting files is easy in java, just write an if…..else block and use the delete() method inside it.
Example:
import java.io.File;
public class DeleteFile {
public static void main(String[] args) {
File file = new File("students.txt");
if (file.delete()) {
System.out.println("Deleted Sccessfully: " + file.getName());
} else {
System.out.println("Error......");
}
}
}
Output:
Deleted Sccessfully: students.txt
Sorry, we detected that you have activated Ad-Blocker.
Please consider supporting us by disabling your Ad-Blocker, it helps us in developing this Website.
Thank you!