删除 java代码中所有的注释

2019-1-4


删除 java代码中所有的注释.java

public class CleanCommons {
    private static Pattern pattern = Pattern.compile("/\\*.+?\\*/", Pattern.DOTALL);

    public static void main(String[] args) throws IOException {
        Collection<File> java = FileUtils.listFiles(new File("E:\\dev\\riskManagement\\rm"), new String[]{"java"}, true);
        for (File file : java) {
            String content = FileUtils.readFileToString(file, "utf-8");
            FileUtils.writeStringToFile(file, cleanCommons(content), "utf-8");
        }
    }

    public static String cleanCommons(String content) {
        content.replaceAll("//.+\\r\\n", "");
        return pattern.matcher(content).replaceAll("");

    }
}

下载地址

百度网盘
密码: