对于文件操作实际上查看下JDK的File类的相关API即可,对于文件夹的删除主要是一个递归,参考代码如下:
01.public void delFolder(String filePath) { 02. 03. File folder = new File(filePath); 04. if(!folder.isDirectory()){ 05. folder.delete(); 06. }else if(folder.isDirectory()){ 07. String [] filelists = folder.list(); 08. for(int i=0;i<filelists.length;i++){ 09. File tempFile = new File(filePath + "\\" + filelists[i]); 10. if(!tempFile.isDirectory()){ 11. tempFile.delete(); 12. }else if(tempFile.isDirectory()){
13. delFolder(filePath + "\\" + filelists[i]); <span style="font-family: Arial, Helvetica, sans-serif;">//递归调用 </span> 14. } 15. } 16. } 17. folder.delete(); 18. }
原文地址:http://blog.csdn.net/posonrick/article/details/46011487