疯狂java讲义习题11.1

xiaoxiao2021-02-28  109

题目描述如下: 定义一个工具类,该类要求用户运行该程序时输入一个路径。该工具会将该路径下(及其子目录下的)所有文件列出来。 代码如下:(第一次用Java写一个像样的程序,有点小激动......)

点击(此处)折叠或打开

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("文件夹是空的");             }                      for (File file:fileList)             {                 if (file.isFile())                 {                     System.out.println("文件名"+file.getAbsolutePath());                 }                 else{                     System.out.println("路径名"+file.getAbsolutePath());                     recv(file.getAbsolutePath());                 }             }             }         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:\冰点文库\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 ’ <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> 阅读(116) | 评论(0) | 转发(0) | 0

上一篇:myeclipse破解

下一篇:疯狂Java讲义习题11.2

相关热门文章 Tomcat 6 配置SSI让Resin支持shtml(SSI)- 静...tomcat + ssiASP JavaScript Lessons(8-14)JDK1.6官方下载_JDK6官方下载_... 给主人留下些什么吧!~~ 评论热议
转载请注明原文地址: https://www.6miu.com/read-60244.html

最新回复(0)