Code line count statistics class

xiaoxiao2021-03-06  80

Package codecount;

/ ** *

title: Code line count statistics class *

Description: After completing the project, I want to see how many lines of code I have "created", * But I have SO, page search To the statistics you want. Under the way, I wrote a * although it's simple, it reached the purpose of using it. I am deeply gratified in my heart. ^ _ ^ * *

Date: 2004-8-24 *

Copyright: Copyright (c) 2004 *

Company: Le Open Studio * @author Chen Shaokun * @version 1.0 * /

Import java.io. *;

Public class codefile {public codefile () {}

/ ** * Test * @Param args * / public static void main (String [] args) {codefile code1 = new codefile (); system.out.println ("Start Time:" New Java.util.date () ); System.out.Println (Codefile1.getCoderows (New File ("E: // Project // Code // Hy"), ".txt, .html, .java, .jsp, .htm, .js ,. CSS ", false); system.out.println (" End Time: " New java.util.date ());}

/ ** * Statistical code line number * @Param file file or directory * @Param Fileterstr strings for the venue of the file to be counted: for example: "java, .jsp, .html.js, .css" * @ Param isblanklie is statistically vacant, True: The blank line is also counted, FALSE: The blank line is not * @return count statistics. * / Public long getCoderows (File File, String Fileterstr, Boolean Isblankline) {long count = 0; if (file.isdirectory ()) {// If it is a directory system.Println ("Path =" file.getpath )); String [] subfiles = file.list (new filefileter (filetr)); system.out.println ("Subfiles and folders =" Subfiles.length); if (Subfiles! = Null) { For (int i = 0; i

} // if (Subfiles! = NULL)

} // Else {// If it is a file // count the code of a file COUNT = Countrow (file, isblankline);

}

Return count;

}

/ ** * Statistical number of rows in a file * @Param file * @return * / private long countrow (file file, boolean isblankline) {long count = 0; try {java.io.bufferedreader BREADER = New java.io. BufferedReader (new java.io. fileReader (file); if (Breader! = Null) {string s = null; while ((s = BReader.readLine ())! = Null) {if (isblankline || S.LENGTH ()> 0) // Statistics or not statistics blank count ; s = null;} BREADER.CLOSE () ;;}} catch (ooException ex) {EX.PrintStackTrace ();} Return Count;}

/ ** * Internal hidden category *

Title: File name is considering class, mainly for files to be statistically confirmed *

Description: *

Copyright: CopyRight (c) 2004 *

Company: Happy Studio * @Author Chen Shaokun * @version 1.0 * / Class FileFileter Implements java.io.FileNameFilter {String FileName; FileFileter (String filename) {this.FileName = filename;

/ * ** interface to achieve that the accept filenameFileter * @param dir * @param name * @return * / public boolean accept boolean flag = false (File dir, String name) {; String filetername [] = filename.split ( ", "); If (filetername! = Null) {// If it is for (int i = 0; i

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-124026.html

New Post(0)