洛神賦

          子虛烏有

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            7 Posts :: 10 Stories :: 0 Comments :: 0 Trackbacks

          要求:
          1、模擬一個病毒 exe文件;
          2、通過IO查找并進行刪除;
          分析:
          1、首先要先建一個刪除的方法;
          2、判斷你要查找的文件中是否有你想要刪除的文件

          import java.io.File;
          import java.io.IOException;

          public class Antivirus {
           

           //定義一個刪除的方法
           public static boolean deleteFile(File source,String suffix)throws IOException{
            if(source == null||!source.exists()){
             System.out.println("無法找到資源!");
            }
            if(source.isDirectory()){
             File[] files = source.listFiles();
               if(files == null||files.length == 0)
                  {
                  System.out.println("該文件沒有你想要查找的!");
                  }
              else{
                   for(File f : files)
                   {
                      deleteFile(f,suffix);
                   }
                }
            }
            else{
             if(source.getName().endsWith(suffix)){
              source.delete();
              if(source.exists()){
               System.out.println("刪除   "+source.getName()+"  失敗!");
              }
              System.out.println("刪除   "+source.getName()+"   成功!");
             }
            }
            return false;
           }
          //主函數
           public static void main(String[] args){
            File f = new File("f:\\");
            try {
             deleteFile(f,"bingdu.exe");
            } catch (IOException e) {
             e.printStackTrace();
            }
           }

          }
          //運行結果:
          只要沒有錯誤就是正確的!


          感謝閱讀!!!!!!!!!

          posted on 2010-11-01 13:46 洛神賦 閱讀(218) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 二连浩特市| 永宁县| 会昌县| 都匀市| 临桂县| 天峻县| 汤原县| 保山市| 平原县| 伊吾县| 增城市| 怀化市| 福建省| 原阳县| 新宁县| 饶平县| 察隅县| 阿巴嘎旗| 孟连| 花莲县| 台江县| 太和县| 泽州县| 叶城县| 潢川县| 沧州市| 会理县| 四平市| 蓬溪县| 浦城县| 石嘴山市| 荣成市| 沁源县| 株洲市| 静乐县| 宜丰县| 富顺县| 罗平县| 毕节市| 合川市| 大英县|