批量删除代码注释
来源:互联网 发布:手机编程百度专用皮肤 编辑:程序博客网 时间:2024/05/22 11:34
最近项目交接,公司业务被被抢了!恼火!!而且还是使用及其下流的手段抢了业务,虽然我不是老板,但是我也是公司一员,删了全部注释,让你们接!!!
此代码并不完善,不能排除一些特殊情况。删了不该删的代码,手工补回来就好了。
public class test { private static int count = 0; /** * 删除文件中的各种注释,包含//、/* * /等 * @param charset 文件编码 * @param file 文件 */ public static void clearComment(File file, String charset) { try { //递归处理文件夹 if (!file.exists()) { return; } if (file.isDirectory()) { File[] files = file.listFiles(); for (File f : files) { clearComment(f, charset); //递归调用 } return; } else if (!file.getName().endsWith(".java")) { //非java文件直接返回 return; } System.out.println("-----开始处理文件:" + file.getAbsolutePath()); //根据对应的编码格式读取 BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); StringBuffer content = new StringBuffer(); String tmp = null; while ((tmp = reader.readLine()) != null) { content.append(tmp); content.append("\n"); } String target = content.toString(); //String s = target.replaceAll("\\/\\/[^\\n]*|\\/\\*([^\\*^\\/]*|[\\*^\\/*]*|[^\\**\\/]*)*\\*\\/", ""); //本段正则摘自网上,有一种情况无法满足(/* ...**/),略作修改 String s = target.replaceAll("\\/\\/[^\\n]*|\\/\\*([^\\*^\\/]*|[\\*^\\/*]*|[^\\**\\/]*)*\\*+\\/", ""); //System.out.println(s); //使用对应的编码格式输出 BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)); out.write(s); out.flush(); out.close(); count++; System.out.println("-----文件处理完成---" + count); } catch (Exception e) { e.printStackTrace(); } } public static void clearComment(String filePath, String charset) { clearComment(new File(filePath), charset); } public static void clearComment(String filePath) { clearComment(new File(filePath), "UTF-8"); } public static void clearComment(File file) { clearComment(file, "UTF-8"); } public static void main(String[] args) { clearComment("D:\\gzlhxc\\lhxc_xg\\src"); //删除目录下所有java文件注释 //删除某个具体文件的注释 //clearComment("D:\\proj\\scm\\action\\AbcdefgAction.java"); }}
0 0
- 批量删除代码注释
- 批量删除Xcode中代码的注释
- 批量删除PDF注释
- 批量删除文件注释
- 批量删除PDF注释
- 批量删除PDF注释
- vim 批量删除注释
- notepad批量删除注释
- C# 代码文件头部注释批量写入, 函数注释批量删除的工具
- VS中批量删除注释
- vim 批量注释及删除注释
- 删除代码中的注释
- 删除代码中的注释
- 删除代码中的注释
- [bash]: 删除代码注释
- vim批量添加删除注释的方法
- vim批量添加删除注释的方法
- vim批量添加和删除注释
- 自绘控件的4种方法
- 关于团队模式开发问题
- 数据结构第二章
- 关键帧动画CAKeyframeAnimation
- ios中模拟手势单击或是双击
- 批量删除代码注释
- IKAnalyzer在Solr下扩充词典
- 黑马程序员-----网络编程
- Android之自定义控件
- ExtJs的数据代理proxy
- 特殊字符及其引用和转义
- JDK中的设计模式
- Tomcat 配置虚拟主机
- 集算器JDBC的集成与使用方法