欢迎来到天天文库
浏览记录
ID:58992694
大小:66.34 KB
页数:4页
时间:2020-10-27
《读取文件夹内所有文件和文件夹.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、还不错建议看下.importjava.io.FileNotFoundException;importjava.io.IOException;importjava.io.File;publicclassReadFile{publicReadFile(){}/***读取某个文件夹下的所有文件*/publicstaticbooleanreadfile(Stringfilepath)throwsFileNotFoundException,IOException{try{Filefile=newFile(filepath);if(!f
2、ile.isDirectory()){System.out.println("文件");System.out.println("path="+file.getPath());System.out.println("absolutepath="+file.getAbsolutePath());System.out.println("name="+file.getName());}elseif(file.isDirectory()){System.out.println("文件夹");String[]filelist=file.
3、list();for(inti=0;i4、tName());}elseif(readfile.isDirectory()){readfile(filepath+"\"+filelist[i]);}}}}catch(FileNotFoundExceptione){System.out.println("readfile()Exception:"+e.getMessage());}returntrue;}/***删除某个文件夹下的所有文件夹和文件*//*publicstaticbooleandeletefile(Stringdelpath)throwsFileNotF5、oundException,IOException{try{Filefile=newFile(delpath);if(!file.isDirectory()){System.out.println("1");file.delete();}elseif(file.isDirectory()){System.out.println("2");String[]filelist=file.list();for(inti=0;i6、+filelist[i]);if(!delfile.isDirectory()){System.out.println("path="+delfile.getPath());System.out.println("absolutepath="+delfile.getAbsolutePath());System.out.println("name="+delfile.getName());delfile.delete();System.out.println("删除文件成功");}elseif(delfile.isDirect7、ory()){deletefile(delpath+"\"+filelist[i]);}}file.delete();}}catch(FileNotFoundExceptione){System.out.println("deletefile()Exception:"+e.getMessage());}returntrue;}*/publicstaticvoidmain(String[]args){try{readfile("e:/videos");//deletefile("D:/file");}catch(FileNo8、tFoundExceptionex){}catch(IOExceptionex){}System.out.println("ok");}}
4、tName());}elseif(readfile.isDirectory()){readfile(filepath+"\"+filelist[i]);}}}}catch(FileNotFoundExceptione){System.out.println("readfile()Exception:"+e.getMessage());}returntrue;}/***删除某个文件夹下的所有文件夹和文件*//*publicstaticbooleandeletefile(Stringdelpath)throwsFileNotF
5、oundException,IOException{try{Filefile=newFile(delpath);if(!file.isDirectory()){System.out.println("1");file.delete();}elseif(file.isDirectory()){System.out.println("2");String[]filelist=file.list();for(inti=0;i6、+filelist[i]);if(!delfile.isDirectory()){System.out.println("path="+delfile.getPath());System.out.println("absolutepath="+delfile.getAbsolutePath());System.out.println("name="+delfile.getName());delfile.delete();System.out.println("删除文件成功");}elseif(delfile.isDirect7、ory()){deletefile(delpath+"\"+filelist[i]);}}file.delete();}}catch(FileNotFoundExceptione){System.out.println("deletefile()Exception:"+e.getMessage());}returntrue;}*/publicstaticvoidmain(String[]args){try{readfile("e:/videos");//deletefile("D:/file");}catch(FileNo8、tFoundExceptionex){}catch(IOExceptionex){}System.out.println("ok");}}
6、+filelist[i]);if(!delfile.isDirectory()){System.out.println("path="+delfile.getPath());System.out.println("absolutepath="+delfile.getAbsolutePath());System.out.println("name="+delfile.getName());delfile.delete();System.out.println("删除文件成功");}elseif(delfile.isDirect
7、ory()){deletefile(delpath+"\"+filelist[i]);}}file.delete();}}catch(FileNotFoundExceptione){System.out.println("deletefile()Exception:"+e.getMessage());}returntrue;}*/publicstaticvoidmain(String[]args){try{readfile("e:/videos");//deletefile("D:/file");}catch(FileNo
8、tFoundExceptionex){}catch(IOExceptionex){}System.out.println("ok");}}
此文档下载收益归作者所有