Sometimes when you delete a directory in Windows, the "source file name length is greater than the length of the system support", and can not be deleted, as a program ape, how can this be impressed by this, on the code:
Import java.io.file;/** * @author Wu Qinglong * October 13, 2015 PM 1:22:33 */public class Deletefiles {public static void Deletefiles ( File file) {if (File.isdirectory ()) {//If it is a directory, first find all files or directories under this directory//and then delete file[] files = file.listfiles (); if (Files.len Gth = = 0) {//If it is an empty directory, delete file.delete directly ();} else {//If it is not an empty directory, then recursive for (File f:files) {deletefiles (f);//After the removal of recursion, delete this directory f.d Elete ();}}} else {//If it is a file, delete file.delete directly ();}} public static void Main (string[] args) {File file = new file ("D:\\Program files\\myeclipse2015");d eletefiles (file);}
This article is from the "focus on Java,linux Technology" blog, please be sure to keep this source http://wuqinglong.blog.51cto.com/9087037/1711598
Cannot delete file, "Source filename is longer than system supported"