java注释 正则表达式_java怎样用正则表达式匹配文档注释,如“/**@date 2012-1-2*/”?...

写了个例子,你可以参照下package iteyeQuestions;

/*

* java怎样用正则表达式匹配文档注释,如“斜杠**@date 2012-1-2*斜杠”?

* 现在想做个把文件的文档注释删除的东西?不知道java怎样用正则表达式来匹配,请各位帮忙

*/

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

public class RidNotation {

//待处理代码文档输入流

private BufferedReader br;

//待处理代码文档输出流

private PrintWriter pw;

//构造方法

public RidNotation(String inputUrl,String outputUrl) throws IOException{

this.br= new BufferedReader(new FileReader(new File(inputUrl)));

this.pw= new PrintWriter(new BufferedWriter(new FileWriter(outputUrl)));;

}

//去文档型注册的方法

public void ridDocType() throws IOException{

String temp=null;

boolean isNotation=false;

while (this.br.ready()) {

temp=this.br.readLine();

int start=0;

int end=0;

if(isNotation){

if((end=temp.indexOf("*/"))==-1){

continue;

}else{//找到注释结束标志

int anotherStart=0;

if((anotherStart=temp.substring(end).indexOf("/**"))==-1){

isNotation=false;//此后为代码段

this.pw.println(temp.substring(end+2));//把本行剩余的代码输出

}else{//又在本行内找到另一个开始标志,输出中间代码

this.pw.println(temp.substring(end+2,anotherStart));

}

}

}else{

if((start=temp.indexOf("/**"))==-1){

this.pw.println(temp);

}else{//找到注释开始标志

if((end=temp.substring(start).indexOf("*/"))==-1){

isNotation=true;//此后为注释段

this.pw.println(temp.substring(0,start));

}else{//此行内同时含有注释结尾标志

this.pw.println(temp.substring(0,start)+temp.substring(end+2));

}

}

}

}

this.br.close();

this.pw.close();

}

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

//测试代码

new RidNotation("RidNotation.java","outttt.txt").ridDocType();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值