In this example we will show the method to delete a folder in Java.
Source Code
package com.beginner.examples;
import java.io.*;
public class DeleteFolder {
public static void main(String[] args )
{
try {
File f = new File("D:\test");
if(f.delete()) { // delete a folder
System.out.println("Deleted successfully!");
} else {
System.out.println("Delete failed.");
}
} catch (IOException e) {
System.out.println("Error.");
e.printStackTrace();
}
}
}
Output:
Deleted successfully!