疯狂java讲义习题11.1

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

点击(此处)折叠或打开

  1. import java.io.*;
  2. import java.util.Scanner;
  3. public class Hello {
  4.     //private static String pa
  5.     public static void recv(String path)
  6.     {
  7.         File newFile = new File(path);
  8.         if (newFile.exists())
  9.         {
  10.             File[] fileList = newFile.listFiles();
  11.             if (fileList.length == 0)
  12.             {
  13.                 System.out.println("文件夹是空的");
  14.             }
  15.         
  16.             for (File file:fileList)
  17.             {
  18.                 if (file.isFile())
  19.                 {
  20.                     System.out.println("文件名"+file.getAbsolutePath());
  21.                 }
  22.                 else{
  23.                     System.out.println("路径名"+file.getAbsolutePath());
  24.                     recv(file.getAbsolutePath());
  25.                 }
  26.             }    
  27.         }
  28.         else
  29.             System.out.println("文件不存在");
  30.     }
  31.     public static void main(String[] args)throws Exception
  32.     {
  33.         Scanner sc = new Scanner(System.in);
  34.         //File newFile = new File("c:");
  35.         //File newFile = new File(path);
  36.         while (sc.hasNext())
  37.         {
  38.             
  39.             recv(sc.next());
  40.             
  41.         }
  42.         
  43.     }
  44.     
  45.     
  46. }
运行结果如下:
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

给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

helloworddm

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值