[Java] import java. io. file; import java. io. fileReader; import java. io. IOException; import java. io. lineNumberReader; import org. apache. commons. lang. stringUtils; public class ProjectCountLine {private static final String JAVA_FILE_SUF = "java"; private static final String CSS_FILE_SUF = "css"; private static final String JS_FILE_SUF = "js "; private static final String JSP_FILE_SUF = "jsp "; Private static final String HTML_FILE_SUF =" html "; private static final String PROPERTIES_FILE_SUF =" properties "; private static final String VM_FILE_SUF =" vm "; // The project and directory private File rootFile = null; // The number of rows of the project private long count = 0L; /*** entry method ** @ param path * root directory path of the Project * @ return * @ throws IOException * @ see [Class, Class # method, class # member] */ public long service (String path) throws IOException {boolean fla G = checkPath (path); if (flag) countFilesLine (rootFile); return count ;} /*** check whether the file is the file type to be counted ** @ param fileName * file name * @ return true: the file is the file to be counted; false: the file is a file that does not require statistics * @ see [Class, Class # method, class # member] */private boolean isCountFileType (String fileName) {if (StringUtils. isBlank (fileName) return false; if (fileName. endsWith (JAVA_FILE_SUF) | fileName. endsWith (CSS_FILE_SUF) | fileName. endsWith (JS_FILE_SUF) | | FileName. endsWith (JSP_FILE_SUF) | fileName. endsWith (HTML_FILE_SUF) | fileName. endsWith (PROPERTIES_FILE_SUF) | fileName. endsWith (VM_FILE_SUF) return true; return false;}/*** check whether the project's root path is correct ** @ param path * Project path * @ return true: the input path is correct; false: the input path is incorrect * @ see [Class, Class # method, class # member] */private boolean checkPath (String path) {if (StringUtils. isBlank (path) return false; rootFile = new File (path); if (! RootFile. exists ()&&! RootFile. isDirectory () return false; return true ;} /*** count the number of lines of files in the specified format in a specified file ** @ param file * specify the file * @ throws IOException * When the file does not exist, an IO exception is thrown * @ see [Class, Class # method, class # member] */private void countFilesLine (File file) throws IOException {File [] files = file. listFiles (); if (null = files) return; for (int I = 0; I <files. length; I ++) {File tempFile = files [I]; String fileName = tempFile. getName (); if (fileName. endsWith ("svn") continue; if (tempFile. isFile () {if (isCountFileType (fileName) {LineNumberReader linReader = new LineNumberReader (new FileReader (tempFile); linReader. skip (Long. MAX_VALUE); count + = linReader. getLineNumber () + 1 ;}} else {// if the current directory is File, recursive countFilesLine (tempFile) ;}} public static void main (String [] args) {ProjectCountLine countLine = new ProjectCountLine (); try {long count = countLine. service ("E :\\ Demo \ java \ eclipse \ afk"); System. out. println (count);} catch (IOException e) {e. printStackTrace ();}}}