zoukankan      html  css  js  c++  java
  • Java统计代码行数

    package test;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    
    public class CodeFontNumber {
    
    	private static String PATH = "D:\source\git\android\he3.sd\app\src\main\java\he3\sd";
    
    	private static int Number = 0;
    
    	private static List<String> JavaCodeFilePath = new ArrayList<>();
    
    	public static void main(String[] args) {
    		getCodeFilePath(PATH);
    		
    		
    		
    		JavaCodeFilePath.forEach(file->{
    			StatisticsCodeNumber(new File(file));
    		});
    		
    		System.out.println(Number);
    		
    	}
    	
    	private static void StatisticsCodeNumber(File file) {
    		try {
    			FileInputStream fis = new FileInputStream(file);
    			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    			String line = null;
    			while ((line = br.readLine())!= null) {
    				Number++;
    			}
    			fis.close();
    			br.close();
    		} catch (FileNotFoundException e) {
    
    			e.printStackTrace();
    		} catch (IOException e) {
    
    			e.printStackTrace();
    		}
    
    	}
    
    	public static void getCodeFilePath(String path) {
    		File file = new File(path);
    		File[] filesArr = file.listFiles();
    		if (filesArr == null) {
    			return;
    		} else {
    			for (File item : filesArr) {
    				if (item.isDirectory()) {
    					getCodeFilePath(item.getPath());
    				} else {
    					if(item.getPath().substring(item.getPath().lastIndexOf(".")).equals(".java"))
    						JavaCodeFilePath.add(item.getPath());
    				}
    			}
    		}
    	}
    }
    
  • 相关阅读:
    微信公众号迁移配置注意点
    关于memcache 命令查看和 Telnet
    centOS 安装(光安装 和 u盘安装)
    CentOS删除自带的java,安装新java
    ubuntu常用命令
    ubuntu 的挂起与休眠
    saiku应用的调试
    数据挖掘123
    unbutu 安装java教程
    workbench的schema讲解一:(维度dimension设置的基本内容)
  • 原文地址:https://www.cnblogs.com/yangchaojie/p/9660799.html
Copyright © 2011-2022 走看看