A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© mengxun 中级黑马   /  2015-7-29 21:07  /  211 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. package com.baidu;

  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;

  5. /**
  6. * @program 此程序为了检索目标电脑中所有磁盘下的隐藏文件(为何隐藏,你们懂的)
  7. *                         中间有彩蛋
  8. * @author 玲海 , 杨洋
  9. * @version 2.0
  10. */
  11. public class DiGuiSearch {
  12.         static int count = 0;
  13.         static int ycount = 0;

  14.         public static void main(String[] args) throws IOException {
  15.                 File[] filarr = File.listRoots();
  16.                 for (File file : filarr) {
  17.                         System.out.println(file.getAbsolutePath());
  18.                         Search(file);
  19.                 }
  20.                 System.out.println("隐藏文件夹个数:" + count); // 不可放入Search方法中,因为随着递归,不断重新归零
  21.                 System.out.println("隐藏文件个数:" + ycount);
  22.                 //写入挑衅语句
  23.                 //??????????????如何获取对方电脑桌面路径
  24.                 FileWriter fw = new FileWriter("C:\\Users\\玲海\\Desktop\\神偷留言.txt");
  25.                 fw.write("xxx文件已取走,thank you 我是雷锋");
  26.                 fw.flush();
  27.                 fw.close();   //即使是对方电脑也要关闭流
  28.                
  29.         }

  30.         public static void Search(File path) {
  31.                 File[] fil = path.listFiles();
  32.                 if (!(fil == null)) {
  33.                         for (File file : fil) {
  34.                                 if (file.isDirectory()) {
  35.                                         if (file.isHidden()) {
  36.                                                 count++;
  37.                                                 // System.out.println("隐藏文件夹:" +
  38.                                                 // file.getAbsolutePath());
  39.                                         }
  40.                                         Search(file);
  41.                                 } else {
  42.                                         if (file.getName().endsWith(".mp3") && file.isHidden()) {
  43.                                                 // System.out.println("隐藏文件:" + file.getAbsolutePath());
  44.                                                 ycount++;
  45.                                         }// else---if
  46.                                 }// else
  47.                         }// for
  48.                 }// if非空
  49.         }// 函数
  50. }// 类
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马