Original
/** Delcomment.java * Copy This file to Copy.java, * and get rid of the comments. * * Author: Li Wenxiong. 033534026 * Class: E-Government * * time:04-08-2005 * * can put some//and/or nested annotations can also be removed, * can also distinguish those are strings of characters, rather than annotations. * Complete function is better * */package class;import java.io.*;
public class Delcomment{ private static void OutLine (BufferedWriter out,string Line, int n) { //Us Ed to write to the outfile string s = "First" + N + "line:"; line = s + line; try{&n Bsp; out.write (line); out.newline (); } catch (IOException e) { e.printstacktrace (); } } public static void Main (string[] args) { //main function int n = 0; //the line number String line = ""; //used to load the string string temp = ""; int cmtIndex0 = -1;&N bsp; //is used to mark string Quotes " int cmtIndex4 = -1; int CmtIndex1 = -1; // Used to mark the annotation symbol// int CMTINDEX2 = -1; //to mark the annotation symbol/* */ Boolean ISCMT1 = false; //used to mark annotation symbols// booleanISCMT2 = false; //For marking annotation symbols/* */ try{ BufferedReader in = new BufferedReader (new InputStreamReader (New FileInputStream ("Delcomment.java")); //bufferedwriter out = new BufferedWriter (New FileWriter ("Copy.java")), bufferedwriter out = New BufferedWriter (New OutputStreamWriter FileOutputStream ("Copy.java")); while (temp = In.readline ())!= null) {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CMTINDEX2 = Temp.indexof ("* *"); if (CmtIndex2!=-1) && ISCMT2) { iscmt2 = False; line = Temp.substring (cmtindex2+2); n++; OutLine (out,line,n); continue; } if (ISCMT2) continue; cmtindex0 = Temp.indexof ("\"); //Opening quote "position cmtindex1 = Temp.indexof ("//"); cmtindex2 = Temp.indexof ("/*"); cmtindex4 = Temp.indexof ("\", cmtIndex0+1); //the position of the closing quote " if" ( (CmtIndex0 < CMTINDEX1) && (CmtIndex1 < cmtIndex4)) ( ) { & nbsp; // "//" is not between two quotes if ( CmtIndex1!=-1) { if (CmtIndex1 < cmtIndex2) | | (CmtIndex2 = = 1)) if (cmtIndex1 > 0) { line = temp.substring (0,cmtINDEX1); n++; outline (out,line,n); continue; } } } if ( (CmtIndex0 < CMTINDEX2) && (CmtIndex2 < cmtIndex4)) { & nbsp // "/*" is not between two quotes if ( CmtIndex2!=-1) { if (cmtIndex2 > 0) { line = temp.substring (0,cmtindex2); n++; outline (out,line,n); } &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ISCMT2 = true; continue; } } n++; outline (out,temp,n); } in.close (); out.close (); }catch (EOFException e) {} //catch the Exception catch (IOException e) { e.printstacktrace (); } catch (Exception e) { e.printstacktrace (); } //********* those below just for test ' get rid of comment ' string str1 = '// & nbsp This is just to test about (//); string str2 = "/* this are just to test about (/* *) */" system.out.println (STR1); system.out.println (str2); }}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.