단순 통계 코드 행수
테스트 프로그램과 함께 여러분의 조언을 바랍니다 -->
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
/**
 * File: Counter.java
 * User: z3y2
 * Date: 2010-12-30
 * Time:   04:58:03
 * Copyright: (c) 2010 All Rights Reserved
 */
/**
 * @author z3y2
 */
public class Counter {
	static long l = 0;
	static long fileCount = 0;
	static long nullLineCount = 0;
	static long total = 0;
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		String path = Counter.class.getResource("/").getPath().substring(1);
		java.io.File classpath = new java.io.File(path);
		String srcpath = classpath.getParentFile().getParentFile().getParentFile().getAbsolutePath();
		if (!srcpath.endsWith(File.separator)) {
			srcpath += File.separator;
		}
		srcpath += "src" + File.separator;
		File srcFile = new File(srcpath);
		readFile(srcFile);
		System.out.println("      :" + fileCount);
		System.out.println("       :" + total + ",        :" + l + ",     :" + nullLineCount);
	}
	static void readFile(File file) throws Exception {
		if (file.isDirectory()) {
			for (File f : file.listFiles()) {
				readFile(f);
			}
		} else if (file.getName().endsWith(".java")) {
			fileCount ++;
			System.out.println("      :" + file.getAbsolutePath()); 
			FileInputStream in = new FileInputStream(file);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			for (String line = br.readLine(); line != null; line = br.readLine()) {
				if (line.trim().length() == 0) {
					nullLineCount ++;
				} else {
					l ++;
				}
				total ++;
			}
			in.close();
			br.close();
		}
	}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
소스 코드가 포함된 Python 프로젝트텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.