Calculate the number of lines of code under all packages in a project

Source: Internet
Author: User

Sometimes, when archiving a project, we will inevitably encounter statistics on the number of lines of code. In this case, we can use a piece of code to directly calculate the number of lines.

Below is an example code for counting the number of lines of code in a Java project:

Import Java. io. file; import jodd. io. fileutil; public class test {public static void main (string [] ARGs) throws exception {file root = new file ("E:/myeclipse 9/"); showallfiles (Root ); system. out. println (n);} static int N; Final Static void showallfiles (File DIR) throws exception {file [] FS = dir. listfiles (); For (INT I = 0; I <FS. length; I ++) {system. out. println (FS [I]. getabsolutepath (); If (FS [I]. getabsolutepath (). endswith (". java ") {string [] STR = fileutil. readlines (FS [I]. getabsolutepath (); For (string S: Str) {If (S. length ()> 0) {n ++; // system. out. println (s) ;}} if (FS [I]. isdirectory () {try {showallfiles (FS [I]);} catch (exception e ){}}}}}

Calculate the number of lines of code under all packages in a project

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.