We would like to know how to delete file or directory when the program ends.
import java.io.File; public class MainClass { public static void main(String[] a) { File file = new File("c:\\test\\test.txt"); file.deleteOnExit(); } }
The code above generates the following result.