|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
先说优点,首先和C,C++这些语言比起来,java很简单,去掉指针的java,非常好理解,自动垃圾回收机制也很好,自从JDK1.5推出以后,性能上又有了很大提高。原创
/**DelComment.java**CopythisfiletoCopy.java,*andgetridofthecomments.**Author:李文雄。033534026*Class:电子政务**Time:04-08-2005**能够把一些//和/*嵌套的正文也可以往失落,*别的也能够区分出那些是字符串的字符,而不是正文。*完成的功效对照好**/packageClass;importjava.io.*;
publicclassDelComment{privatestaticvoidoutLine(BufferedWriterout,Stringline,intn){//UsedtowritetotheoutfileStrings="第"+n+"行:";line=s+line;try{out.write(line);out.newLine();}catch(IOExceptione){e.printStackTrace();}}publicstaticvoidmain(String[]args){//MainFunctionintn=0;//notethelinenumberStringline="";//UsedtoloadthestringStringtemp="";intcmtIndex0=-1;//用来标志字符串引号"intcmtIndex4=-1;intcmtIndex1=-1;//用来标志正文标记//intcmtIndex2=-1;//用来标志正文标记/**/booleanisCmt1=false;//用来标志正文标记//booleanisCmt2=false;//用来标志正文标记/**/try{BufferedReaderin=newBufferedReader(newInputStreamReader(newFileInputStream("DelComment.java")));//BufferedWriterout=newBufferedWriter(newFileWriter("copy.java"));BufferedWriterout=newBufferedWriter(newOutputStreamWriter(newFileOutputStream("copy.java")));while((temp=in.readLine())!=null){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(""");//呈现左引号"的地位cmtIndex1=temp.indexOf("//");cmtIndex2=temp.indexOf("/*");cmtIndex4=temp.indexOf(""",cmtIndex0+1);//呈现右引号"的地位if(!((cmtIndex0<cmtIndex1)&&(cmtIndex1<cmtIndex4))){//"//"不是在两个引号之间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))){//"/*"不是在两个引号之间if(cmtIndex2!=-1){if(cmtIndex2>0){line=temp.substring(0,cmtIndex2);n++;outLine(out,line,n);}isCmt2=true;continue;}}n++;outLine(out,temp,n);}in.close();out.close();}catch(EOFExceptione){}//catchtheexceptioncatch(IOExceptione){e.printStackTrace();}catch(Exceptione){e.printStackTrace();}//*********Thosebelowjustfortestof"Getridofcomment"Stringstr1="//Thisisjusttotestabout(//)";Stringstr2="/*Thisisjusttotestabout(/**/)*/";System.out.println(str1);System.out.println(str2);}}
==>输入了局:
http://blog.csdn.net/horisly/archive/2005/04/08/340159.aspx
专门做了这个例子;而java的这个例子好像就是为了教学而写的,很多教学目的的例子是不考虑优化、性能的。 |
|