查询一个项目大代码行数

package springboot_001.main;

/**
 * @author bwx686385 bianqiang
 * @create 2020/5/6
 */
import org.apache.commons.lang.StringUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;



import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;

/**
 * @author xWX620347
 *
 */
public class Test {
    public static void main(String[] args) throws Exception {
        listFile(new File("D:\\idea_workspace\\ows_csp"));
        System.out.println(fileCount);
        System.out.println(lineCount);
    }

    public static Map<String, Integer> fileCount = new LinkedHashMap<>();
    public static Map<String, Integer> lineCount = new LinkedHashMap<>();

    public static Set<String> fileLineExt = new HashSet() {{
        add("java");
        add("html");
        add("js");
        add("css");
    }};

    public static void listFile(File file) throws Exception {
        if (file.isDirectory() && file.listFiles() != null) {
            if (".git".equals(file.getName())) {
                return;
            }
            for (File f : file.listFiles()) {
                listFile(f);
            }
        } else {
            String name = file.getName();
            String ext = null;
            if (name.contains(".")) {
                ext = name.substring(name.lastIndexOf(".") + 1);
            }
            if (StringUtils.isEmpty(ext)) {
                return;
            }
            if (ext.length() < 1 || ext.length() > 4) {
                return;
            }
            if (fileLineExt.contains(ext)) {
                Integer count = fileCount.get(ext);
                if (count == null) {
                    count = 1;
                } else {
                    count++;
                }
                fileCount.put(ext, count);
                Integer line = lineCount.get(ext);
                if (line == null) {
                    line = 0;
                }
                line += getFileLinesCount(file);
                lineCount.put(ext, line);
            }
        }
    }

    public static int getFileLinesCount(File file) throws Exception {
//        long fileLength = file.length();
//        LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(file));
//        lineNumberReader.skip(fileLength);
//        int lines = lineNumberReader.getLineNumber();
//        lineNumberReader.close();
//        return lines;
        long lines = 0;
        try {
            lines = Files.lines(Paths.get(file.getPath())).count();
        } catch (Exception ex) {

        }
        return (int) lines;
    }




}

https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/combine/chapter3_1.shtml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值