自己写的Java垃圾文件清理

2012-11-12

  自己没事儿写的垃圾文件情理,算法很垃圾。凑合着能用。

  =====================================================================

  package com.datatransfer;

  import java.io.File;

  import java.io.IOException;

  import java.text.SimpleDateFormat;

  import java.util.Date;

  import java.util.HashMap;

  import javax.swing.JFileChooser;

  public class test {

  // tmp *._mp *.log *.gid *.chk *.old *.dmp *.bak *.hlp temp internet

  static String[] SYSARRAY = { "tmp", "_mp", "gid", "chk", "old",

  "dmp", "bak", "hlp", "temp", "internet" };

  static HashMap<String,Integer> map = new HashMap<String,Integer>(); //删除结果分类

  static StringBuffer sb = new StringBuffer(); //删除结果详细

  static long count = 0; //删除个数

  static long scanCount = 0; //扫描个数

  static long node = 0; //子文件夹

  /**

  * @param args

  * @author 2010-3-30上午10:06:06By Simon (赵振明).

  * @throws IOException

  */

  public static void main(String[] args) throws IOException {

  test t = new test();

  java.util.Date now = new Date();

  t.listFile("D://");

  java.util.Date date=new Date();

  TDoA(date,now);

  System.err.println("共扫描 :" + scanCount + "个文件");

  System.err.println("共删除了 :" + count + "个文件");

  for (String str : SYSARRAY) {

  System.err.println("共删除【"+str+"】类型垃圾文件 :"+map.get(str)+"个");

  }

  System.err.println("=====================详细信息=====================");

  System.err.println(sb.toString());

  }

  /**

  * 获取文件夹下的所有文件

  *

  * @author 2010-3-30上午10:56:51By Simon (赵振明).

  */

  public void listFile(String pash) {

  File f = new File(pash);

  File[] array = f.listFiles();

  //JFileChooser j = new JFileChooser();

  for (File file : array) {

  if (file.isDirectory()) {

  this.File(file);

  } else {

  System.out.println("扫描文件:" + file.getPath());

  if (trimExtension(file.getName())) {

  // System.err.println("删除 :"+file.getPath());

  file.delete();

  count++;

  sb.append("删除了:" + file.getPath());

  sb.append("/n");

  }

  // System.err.println(j.getTypeDescription(file));

  }

  }

  }

分享到:
0
相关阅读
友情链接
© 2018 我考网 http://www.woexam.com 中国互联网举报中心 湘ICP备18023104号 京公网安备 11010802020116号
违法和不良信息举报:9447029@qq.com