Java编写的重命名工具

package com.exe;

import java.awt.Dialog.ModalExclusionType;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.JList;
import java.awt.Toolkit;

public class Rename extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private File[] fileArray;
	private String root;
	private File ParentFolder;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Rename frame = new Rename();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Rename() {
		setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Administrator\\Desktop\\re.PNG"));
		setModalExclusionType(ModalExclusionType.TOOLKIT_EXCLUDE);
		setTitle("\u91CD\u547D\u540D\u5DE5\u5177");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(null);
		setContentPane(contentPane);
		
		
		
		textField = new JTextField();
		textField.setBounds(78, 13, 289, 24);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel label = new JLabel("\u7236\u76EE\u5F55:");
		label.setBounds(14, 16, 72, 18);
		contentPane.add(label);
		
		JButton button = new JButton("\u6267\u884C\u91CD\u547D\u540D");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				root=textField.getText().trim();
				ParentFolder =new File(root);
				System.out.println("root is: "+root);
				fileArray=ParentFolder.listFiles();
				for (int i = 0; i < fileArray.length; i++) {
					System.out.println("子文件"+i+": "+fileArray[i].getName());
					String name=fileArray[i].getName();
					String names[];
					if(name.endsWith(".md5")){
						names=name.split(".md5");
						name=names[0];
						name=root+"\\"+name;
						System.out.println("name is "+name);
						File newFile=new File(name);
						fileArray[i].renameTo(newFile);
					}
				}
				
			}
		});
		button.setBounds(137, 50, 113, 27);
		contentPane.add(button);
		
	}
}
 
 
效果如图:
 
 

Java编写的重命名工具_第1张图片

你可能感兴趣的:(Java编写的重命名工具)