ตัวอย่างมีดังนี้:
แพ็คเกจ com.xx; นำเข้า java.io.file; การทดสอบคลาสสาธารณะ {โมฆะคงที่สาธารณะหลัก (สตริง [] args) {สตริง fileroot = "c:/ผู้ใช้/xx/เดสก์ท็อป/xx/xxx"; Delfolder (Fileroot); System.out.println ("ลบ");} //// ลบโฟลเดอร์หลังจากลบไฟล์ //// param โฟลเดอร์โฟลเดอร์เต็มเส้นทาง Absolute Path Public Public Delelder (String FolderPath) {ลอง {DelallFile (FolderPath); // ลบทุกอย่างภายใน // ไม่ต้องการลบโฟลเดอร์ Wenjia และซ่อน // String filePath = FolderPath; // filePath = filePath.ToString (); // java.io.file myFilepath = new Java.io.file (filepath); // ลบโฟลเดอร์ว่างเปล่า} catch (Exception e) {E.printStackTrace ();}} // ลบไฟล์ทั้งหมดในโฟลเดอร์ที่ระบุ // param path โฟลเดอร์เต็มเส้นทาง Absolute Path Public Static Boolean DelallFile (เส้นทางสตริง) if (! file.exists ()) {return flag;} if (! file.isdirectory ()) {return flag;} string [] templist = file.list (); ไฟล์ temp = null; สำหรับ (int i = 0; i <templist.length; {temp = ไฟล์ใหม่ (path + file.Sparator + templist [i]);} ถ้า (temp.isfile ()) {temp.delete ();} ถ้า (temp.isdirectory ()) {delallfile (path + "/" + templist [i]) จากนั้นลบธงโฟลเดอร์ว่าง = true;}} return flag;}}ตัวอย่างข้างต้นของ Java การลบเนื้อหาทั้งหมดในโฟลเดอร์โดยไม่ต้องลบโฟลเดอร์เองคือเนื้อหาทั้งหมดที่ฉันแบ่งปันกับคุณ ฉันหวังว่าคุณจะให้ข้อมูลอ้างอิงและฉันหวังว่าคุณจะสนับสนุน wulin.com มากขึ้น