package com.jachs.mvc; import java.*; import ch.qos.logback.classic.net.SyslogAppender; /**** * * @author zhanchaohan * */ public class testFile { //一段注释 public String name; /**** * 多行注释 * @return */ public String getText() { return this.name; } //又是一行注释 private void syso() { System.out.println("打印"); } }
以上是测试用的java类。
一下是去除注释代码
package com.jachs.mvc; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.ArrayList; import java.util.List; import java.util.Random; import org.apache.commons.lang3.RandomUtils; import org.junit.Test; import com.fasterxml.jackson.databind.util.ArrayBuilders.BooleanBuilder; import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; public class test { @Test public void test() { try { File file=new File("C:\\Users\\Jachs\\Downloads\\mvc\\src\\main\\java\\com\\jachs\\mvc\\testFile.java"); BufferedReader br=new BufferedReader(new FileReader(file)); String line=""; boolean breakContinue=false; while(br.ready()) { line=br.readLine(); if(line.trim().startsWith("//")) { continue; } if(line.trim().startsWith("/*")) { breakContinue=true; } if(line.trim().endsWith("*/")) { breakContinue=false; continue; } if(!breakContinue) System.out.println(line); } br.close(); }catch(Exception e) { e.printStackTrace(); } } }