Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement Code Statistics Mini Program by java

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces java how to achieve code statistics Mini Program, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The details are as follows

You can test your weekly workload.

Package rexExp; import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException; public class CodeCounter {/ / three static variables store rows static long normalLines = 0; static long commentLines = 0; static long whileLines = 0; public static void main (String [] args) {String pathname = "E:\ testeclipseworkspace\\ JavaLearn\\ src\ collection"; File file = new File (pathname); File [] codeFiles = file.listFiles () / / find all subfiles under the folder / / files must end with .java, use regular expressions to validate for (File child: codeFiles) {if (child.getName (). Matches (". *\\ .java $") {parse (child);}} System.out.println ("normalLines:" + normalLines); System.out.println ("commentLines:" + commentLines); System.out.println ("whileLines:" + whileLines) } private static void parse (File file) {BufferedReader bReader = null; boolean comment = false; try {bReader = new BufferedReader (new FileReader (file)); / / read each line String line= ""; while ((line=bReader.readLine ())! = null) {line= line.trim (); / / remove leading and trailing spaces / / count the number of blank lines if (line.matches ("^ [\ slots & [^\ n]] * $")) {whileLines++ } / / count the number of lines of comments else if (line.startsWith ("/ *") & &! line.endsWith ("* /")) {commentLines++; / / if "/ *" is encountered, the comment starts with comment = true;} else if (line.startsWith ("/ *") & & line.endsWith ("* /")) {commentLines++;} else if (true = = comment) {commentLines++ If (line.endsWith ("* /")) {comment = false;}} else if (line.startsWith ("/ /")) {commentLines++;} else {normalLines++;} catch (FileNotFoundException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace ();} finally {if (bReader! = null) {try {bReader.close ();} catch (IOException e) {e.printStackTrace () }}} Thank you for reading this article carefully. I hope the article "how to implement Code Statistics Mini Program in java" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report