In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.