Import Java. io. bufferedreader; <br/> Import Java. io. file; <br/> Import Java. io. filenotfoundexception; <br/> Import Java. io. filereader; <br/> Import Java. io. ioexception; </P> <p>/** <br/> * <SPAN class = 'wp _ keywordlink '> Code </span> row count Statistics <br/> * @ author fog non-fog <br/> * @ date 2011-05-25 <br/> */<br/> public class statisticcodelines {</P> <p> Public static int normallines = 0; // valid <SPAN class = 'wp _ keywordlink '> Program </span> Number of rows <br/> Public static int whitelines = 0; // Number of blank rows <br/> Public static int commentlines = 0; // Number of comment rows </P> <p> Public static void main (string [] ARGs) throws ioexception {</P> <p> file = new file ("D: // workspace // project "); <br/> If (file. exists () {<br/> statistic (File); <br/>}< br/> system. out. println ("total valid code lines:" + normallines); <br/> system. out. println ("Total number of blank rows:" + whitelines); <br/> system. out. println ("Total comment Number of rows: "+ commentlines); <br/> system. out. println ("Total number of rows:" + (normallines + whitelines + commentlines); <br/>}</P> <p> Private Static void statistic (File file) throws ioexception {</P> <p> If (file. isdirectory () {<br/> file [] files = file. listfiles (); <br/> for (INT I = 0; I <files. length; I ++) {<br/> statistic (files [I]); <br/>}< br/> If (file. isfile () {<br/> // file with the statistic extension of Java <br/> If (file. getname (). Matches (". *//. java ") {<br/> parse (File ); <br/>}</P> <p> Public static void parse (File file) {<br/> bufferedreader BR = NULL; <br/> // determines whether the row is a comment row <br/> Boolean comment = false; <br/> int temp_whitelines = 0; <br/> int temp_commentlines = 0; <br/> int temp_normallines = 0; </P> <p> try {<br/> Br = new bufferedreader (New filereader (File); <br/> string line = ""; <br/> while (line = BR. readline () )! = NULL) {<br/> line = line. trim (); <br/> If (line. matches ("^ [// S & [^/n] * $") {<br/> // empty rows <br/> whitelines ++; <br/> temp_whitelines ++; <br/>} else if (line. startswith ("/*")&&! Line. endswith ("*/") {<br/> // commentlines starting with "/*" <br/> commentlines ++; <br/> comment = true; <br/>} else if (comment = true &&! Line. endswith ("*/") {<br/> // a row in a multi-line comment (not the beginning or end) <br/> commentlines ++; <br/> temp_commentlines ++; <br/>} else if (comment = true & line. endswith ("*/") {<br/> // end line of multi-line comment <br/> commentlines ++; <br/> temp_commentlines ++; <br/> comment = false; <br/>} else if (line. startswith ("//") {<br/> // comment row <br/> commentlines ++; <br/> temp_commentlines ++; <br/>} else {<br/> // normal code line <br/> normallines ++; <br/> temp _ Normallines ++; <br/>}</P> <p> system. out. println ("valid rows" + temp_normallines + <br/> ", blank rows" + temp_whitelines + <br/> ", comment rows" + temp_commentlines + <br/> ", total number of rows "+ (temp_normallines + temp_whitelines + temp_commentlines) + <br/>" + file. getname (); </P> <p>} catch (filenotfoundexception e) {<br/> E. printstacktrace (); <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}finally {<Br/> If (BR! = NULL) {<br/> try {<br/> Br. close (); <br/> Br = NULL; <br/>}catch (ioexception e) {<br/> E. printstacktrace (); <br/>}</P> <p>}