[Code application] The javaSE program recursively deletes the source code of the. bak file program in the folder.
Author: sushengmiyan
Certificate ------------------------------------------------------------------------------------------------------------------------------------
Now writing JavaScript code is used to writing code using editplus, but every time it is generated, a temporary editplus file is automatically generated. bak, it seems uncomfortable, so we simply write a delete program. When editplus is used to edit the code, double-clicking the jar file will save a lot of trouble.
A simple program contains some small processes for packaging and releasing jar files:
1. Create a project deletebakfiles
2. Create a project package com. susheng. deletebakfiles
3. Create a new class MainDelete under the package and type the code
The Code is as follows:
Package com. susheng. deletebakfiles; import java. io. file; // import javax. swing. JOptionPane; import javax. swing. JOptionPane; import com. susheng. deletebakfiles. util. getCurPath; public class MainDelete {// recursively delete all files in the specified path. public static void deleteBak (File file) {if (file. isFile () {if (file. getAbsolutePath (). endsWith (. bak) {// JOptionPane. showMessageDialog (null, file. getAbsolutePath (), current path, JOptionPane. INFORMATION_MESSAGE); file. delete () ;}} else {File [] files = file. listFiles (); for (File f: files) {deleteBak (f); // recursively Delete each File} public static void main (String [] args) {GetCurPath path = new GetCurPath (); String filePath = path. getCurPath (); File file = new File (filePath); deleteBak (file); JOptionPane. showMessageDialog (null, deleted successfully, current path, JOptionPane. INFORMATION_MESSAGE );}}
4. Create a new class GetCurPath under the com. susheng. deletebakfiles. util package.
Type Code
Package com. susheng. deletebakfiles. util; import javax. swing. JOptionPane; public class GetCurPath {public String getCurPath () {JOptionPane. showMessageDialog (null, System. getProperty (user. dir), current path, JOptionPane. INFORMATION_MESSAGE); // System. out. println (System. getProperty (user. dir); return System. getProperty (user. dir );}}
5. package it into a jar package. Release:
Select eclispe --- export -- java -- jar and choose the output directory "OK" at "next ".
Download the project code and jar package here:
Http://download.csdn.net/detail/sushengmiyan/7885807
Usage: place the jar file in bin in the folder to be deleted, and double-click to run it.
The current path is displayed in the dialog box:
Delete again. Wait until the deletion is completed.