[Code application] The javaSE program recursively deletes the source code of the. bak file program in the folder.

Source: Internet
Author: User

[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.

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.