标签:
package cn.stat.p1.file; import java.io.File; public class newfilelist { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub File f1=new File("E:\\BaiduYunDownload"); nlist(f1,0); } public static void nlist(File f1,int len) { File[] name=f1.listFiles(); for(int x = 0;x<name.length;x++) { if(name[x].isDirectory()) { System.out.print("|-"); for(int y=0;y<len;y++) { System.out.print("-"); } System.out.println(name[x].getAbsolutePath()); nlist(name[x],len+1); }else { System.out.print("|-"); for(int y=0;y<len;y++) { System.out.print("-"); } System.out.println(name[x].getAbsolutePath()); } } } }
删除
package cn.stat.p1.file; import java.io.File; public class filedel { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub File f1=new File("E:\\s2"); delfile(f1,0); } private static void delfile(File f1, int len) { // TODO Auto-generated method stub File[] filename=f1.listFiles(); for(int x=0;x<filename.length;x++) { if(filename[x].isDirectory()) { delfile(filename[x], len+1); System.out.println(filename[x]+"删除:"+filename[x].delete()); } else { System.out.println(filename[x]+"删除:"+filename[x].delete()); } } } }
标签:
原文地址:http://www.cnblogs.com/zywf/p/4776902.html