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());
				}
			}
		}
	}
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM