点击(此处)折叠或打开
import java.io.*; import java.util.Scanner; public class Hello { //private static String pa public static void recv(String path) { File newFile = new File(path); if (newFile.exists()) { File[] fileList = newFile.listFiles(); if (fileList.length == 0) { System.out.println("文件夹是空的"); } int countName = 0,countPath = 0; for (File file:fileList) { if (file.isFile()) { System.out.println("文件名"+file.getAbsolutePath()); countName++; } else{ System.out.println("路径名"+file.getAbsolutePath()); countPath++; recv(file.getAbsolutePath()); } } //System.out.println("文件名"+file.getAbsolutePath()+countName+"路径名"+file.getAbsolutePath()+countPath); System.out.println("countNmae = "+countName+"countPath = "+countPath); } else System.out.println("文件不存在"); } public static void main(String[] args)throws Exception { Scanner sc = new Scanner(System.in); //File newFile = new File("c:"); //File newFile = new File(path); while (sc.hasNext()) { recv(sc.next()); } } } 运行结果: F:\冰点文库 文件名F:\冰点文库\11-论文综述.docx 文件名F:\冰点文库\11文献阅读成绩报告单.doc 文件名F:\冰点文库\11研究生开题申请表.doc 文件名F:\冰点文库\Google.ProtocolBuffers.dll 路径名F:\冰点文库\images 文件名F:\冰点文库\images\ttt countNmae = 1countPath = 0 文件名F:\冰点文库\Update.exe 文件名F:\冰点文库\Update.exe.CodeAnalysisLog.xml 文件名F:\冰点文库\Update.exe.lastcodeanalysissucceeded 文件名F:\冰点文库\Update.pdb 文件名F:\冰点文库\UrlManager_Win32.exe 文件名F:\冰点文库\UrlManager_Win32.pdb 文件名F:\冰点文库\UrlManager_Win32.vshost.exe 文件名F:\冰点文库\UrlManager_Win32.vshost.exe.manifest 文件名F:\冰点文库\开题报告Final.doc 文件名F:\冰点文库\开题报告评审表.doc 文件名F:\冰点文库\论文工作计划.doc countNmae = 15countPath = 1 <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 阅读(93) | 评论(0) | 转发(0) | 0上一篇:疯狂java讲义习题11.1
下一篇:疯狂Java讲义习题11.3
相关热门文章 Tomcat 6 配置SSI让Resin支持shtml(SSI)- 静...tomcat + ssiASP JavaScript Lessons(8-14)JDK1.6官方下载_JDK6官方下载_... 给主人留下些什么吧!~~ 评论热议