예는 다음과 같습니다.
package com.xx; import java.io.file; public class test {public static void main (String [] args) {String fileroot = "c :/users/xx/xxtop/xx/xxx"; Delfolder (Fileroot); system.out.println ( "deleted");} //// 파일을 삭제 한 후 폴더 삭제 //// param 폴더 경로 전체 경로 공개 정적 void delfolder (string folderpath) {try {delallfile (폴더 스팟); // 내부의 모든 것을 삭제 // wenjia 폴더를 삭제하고 다음 // string filepath = folderPath; // filepath = filepath.toString (); // java.io.file myFilePath = new java.io.file (filepath); // myfilepath.delete (); // 빈 폴더를 삭제} catch (예외 e) {e.printstacktrace ();}} // 지정된 폴더의 모든 파일 삭제 // param path 폴더 전체 절대 경로 공개 정적 boolean delallfile (String Path) {boolean flag = false; file file = 새 파일 (path); if (! file.exists ()) {return flag;} if (! file.isdirectory ()) {return flag;} string [] templist = file.list (); file temp = null; for (int i = 0; i <templist.length; i ++) {if.endswith (file.separator)) {wath+pile (wath+); {temp = new File (path + file.separator + templist [i]);} if (temp.isfile ()) {temp.delete ();} if (temp.isdirectory ())) {delallfile (path + "/"/" + templist [i]); // 폴더에서 파일을 삭제하십시오 (path +"); 그런 다음 빈 폴더 플래그 = true;}} return flag;}}을 삭제합니다.폴더 자체를 삭제하지 않고 폴더의 모든 내용을 삭제하는 Java의 위의 예는 내가 공유하는 모든 내용입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.