When deleting a file in window, the system prompts that the source file name length is greater than the length supported by the system.
Sometimes, when you delete a directory in windows, the following error occurs: "The source file name length is greater than the length supported by the system", and thus cannot be deleted. As a programmer, how can this problem be solved,
Principle: uses Java to recursively Delete objects.
Code:
Import java. io. file;/*** @ author Wu Qinglong * October 13, 2015 1:22:33 */public class DeleteFiles {public static void deleteFiles (File file) {if (File. isDirectory () {// if it is a directory, first find all the files or directories under this directory // then delete File [] files = file as needed. listFiles (); if (files. length = 0) {// if it is an empty directory, delete the file directly. delete ();} else {// If the directory is not empty, recursive for (File f: files) {deleteFiles (f); // After recursive deletion, delete the directory f. delete () ;}} else {// if it is a file, delete the file directly. delete () ;}} public static void main (String [] args) {File file = new File ("D: \ Program Files \ MyEclipse2015 "); deleteFiles (file );}}