zoukankan      html  css  js  c++  java
  • 用于删除java注释的小程序

    只能删除java文件中每一行中第一次出现的/**/注释
    对java反编译以后的代码注释删除工作有帮助

    删除java单行注释

    01import java.io.BufferedReader;
    02import java.io.BufferedWriter;
    03import java.io.File;
    04import java.io.FileOutputStream;
    05import java.io.FileReader;
    06import java.io.FileWriter;
    07import java.io.OutputStreamWriter;
    08 
    09class ListAllFirst {
    10    public static void main(String[] args) throws Exception {
    11        String fileName = "D:\\dto.syntheticalstatistics.src\\com\\sysway\\boss\\dto\\report\\statistics";
    12        File f = new File(fileName);
    13        print(f);
    14 
    15    }
    16 
    17    public static void print(File f) throws Exception {
    18 
    19        if (f != null) {
    20            if (f.isDirectory()) {
    21                String st2 = f.toString().replace("D:\\", "E:\\");
    22                File fc = new File(st2);
    23                fc.mkdirs();
    24                File[] fileArray = f.listFiles();
    25                if (fileArray != null) {
    26                    for (int i = 0; i < fileArray.length; i++) {
    27                        // 递归调用
    28                        print(fileArray[i]);
    29                    }
    30                }
    31            } else {
    32                // System.out.println(f);
    33                if (f.getName().endsWith(".java")) {
    34                    String stfile = f.toString().replace("D:\\", "E:\\");
    35 
    36                    FileOutputStream fileOutputStream = new FileOutputStream(
    37                            stfile);
    38                    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
    39                            fileOutputStream, "UTF-8");// 或者"GBK"
    40                    BufferedWriter bw = new BufferedWriter(outputStreamWriter);
    41 
    42                    // BufferedWriter bw=new BufferedWriter(new
    43                    // FileWriter(stfile));
    44                    String str = DelCommentsInJava.fun1(f);
    45                    bw.write(str);
    46                    bw.flush();
    47                    bw.close();
    48 
    49                } else {
    50                    String out = f.toString().replace("D:\\", "E:\\");
    51                    BufferedReader reader = new BufferedReader(
    52                            new FileReader(f));
    53                    StringBuilder content = new StringBuilder();
    54                    String tmp = null;
    55                    while ((tmp = reader.readLine()) != null) {
    56                        content.append(tmp);
    57                        content.append("\n");
    58                    }
    59                    String target = content.toString();
    60                    BufferedWriter bw = new BufferedWriter(new FileWriter(out));
    61                    bw.write(target);
    62                    bw.flush();
    63                    bw.close();
    64                    reader.close();
    65                }
    66            }
    67        }
    68    }
    69 
    70}
  • 相关阅读:
    onTouchEvent的参数详解
    test
    List泛型自定义排序
    unity3d camera.culling mask
    云计算实验一
    软件设计——职责链模式之审批处理
    sqlserver配置sa用户
    软件设计——模板方法模式之对数据库的操作
    flask入门
    课程总结+申请加分
  • 原文地址:https://www.cnblogs.com/shihao/p/2749757.html
Copyright © 2011-2022 走看看