jarパッケージの削除

2677 ワード

public class TestDelete {

      private static List<File> files = new ArrayList();



      public static void addJarsIntoList(String path1)

      {

        File dir = new File(path1);

        if (dir.isDirectory()) {

          File[] subFiles = dir.listFiles();

          for (File file : subFiles)

            if (file.isFile())

              if (getFilesuffix(file.getName()).equals("jar"))

                files.add(file);



            else

              addJarsIntoList(file.getAbsolutePath());

        }

      }



      public static void deleteJarsIntoDestinDir(String destDir)

      {

        addJarsIntoList(destDir);

        for (File f : files)

          f.delete();

      }



      public static void main(String[] args) {

        TestDelete testDelet = new TestDelete();

        deleteJarsIntoDestinDir("D:\\path3");

      }



         public static String getFilesuffix(String strs)

          {

            String ss[] =  strs.split("\\.") ;

            return ss[1];

          }

}