删除反编译工具生成的/* 1 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * 删除项目中
 * 
 * @author Sheamus
 *
 */
public class Delete {
    
    //static String tartgetDir = "D:\\";
    static String tartgetDir = "D:\\Test1\\itjds_server\\";
    
    //static String sourceDir = "C:\\Users\\Sheamus\\Desktop\\";
    static String sourceDir = "D:\\Test\\itjds_server\\";
    
    //static String projectName = "itjdsTest";
    static String projectName = "src";
    
    static String encoding = "utf-8";
    
    public static void main(String[] args) {
        //C:\\Users\\Sheamus\\Desktop\\itjds_org (项目路径信息)
        
        //源
        String sourcePath = sourceDir + projectName;
        
        refreshFileList(sourcePath);
    }

    public static void refreshFileList(String sourcePath) {
        File dir = new File(sourcePath);
        File[] files = dir.listFiles();
        
        if (files == null)
        {
            System.out.println("该目录下没有任何一个文件!");
            return;
        }
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                
                //拼接路径
                String absolutePath = files[i].getAbsolutePath();
                String replace = absolutePath.replace(sourceDir, tartgetDir);
                
                //System.out.println(replace);
                
                File repFile = new File(replace);
                //创建文件夹
                if(!repFile.exists()) {
                    repFile.mkdirs();
                }
                refreshFileList(files[i].getAbsolutePath());
            }else {
                String strFileName = files[i].getAbsolutePath();
//                if(strFileName.endsWith(".java")){
                    //拼接路径
                    String replace = strFileName.replace(sourceDir, tartgetDir);
                    
                    //System.out.println(replace);
                    
                    File repFile = new File(replace);
                    
                    if(!repFile.exists())    
                    {    
                        try {    
                            repFile.createNewFile();    
                        } catch (IOException e) {    
                            // TODO Auto-generated catch block    
                            e.printStackTrace();    
                        }    
                    }    
                    
                    InputStreamReader read = null;
                    BufferedReader bufferedReader = null;
                    OutputStreamWriter out = null;
                    BufferedWriter writer = null;
                    
                    try {
                        read = new InputStreamReader(new FileInputStream(files[i]),encoding);
                        bufferedReader = new BufferedReader(read);
                        String lineTxt = null;
                        
                        out = new OutputStreamWriter(new FileOutputStream(repFile),encoding);
                        writer = new BufferedWriter(out);
                        
                        while((lineTxt = bufferedReader.readLine()) != null){
                            
                            if(lineTxt.startsWith("/*") && lineTxt.contains("*/") ) {
                                String substring = lineTxt.substring(lineTxt.indexOf("*/") + 2);
                                writer.append(substring+"\n");
                                writer.flush();
                            } else {
                                writer.append(lineTxt + "\n");
                                writer.flush();
                            }
                            
                            /*if(lineTxt.startsWith("/* Location:") || lineTxt.startsWith(" * Qualified Name:") || lineTxt.startsWith(" * JD-Core Version:")||) {
                                
                            }*/
                            
                        }

                    } catch (Exception e) {
                        System.out.println("读取文件内容出错");
                        e.printStackTrace();
                    }finally{
                        
                        if(writer != null) {
                            try {
                                writer.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        
                        if(out != null) {
                            try {
                                out.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        
                        if(bufferedReader != null) {
                            try {
                                bufferedReader.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        
                        if(read != null) {
                            try {
                                read.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        
                    }
//                }
            }
        }
    }
}


你可能感兴趣的:(删除反编译工具生成的/* 1 */)