java文件行数
1. 如何统计某目录下的java文件代码行数
可以自己写一个小程序,遍历每个文件;
如果是*.java就记录该文件的行数,依次累加。
2. 一个java类标准代码行数范围大概是多少
以1000行为准,超过千行就要考虑类拆分了。
类的代码行数没有特定的行数限制规范。根据实际情况决定。
对于经常使用的java类,代码行数应该尽可能的少,这样能减少java类的加载时间,减少内存频繁占用和回收。如果类过大,java类加载会耗时并且占用内存大。容易引起内存回收。
3. java怎么读取txt文件的行数
importjava.io.File;
importjava.io.RandomAccessFile;
/**
*读取文档的第二行内容
*
*@author33062017年3月21日
*@see
*@since1.0
*/
publicclassCountLine{
/*
*读取文件绝对路径
*/
privatestaticStringfilePath="d:/cms.sql";
publicstaticvoidmain(String[]args){
longline=readLine(filePath);
System.out.println(line);
}
/**
*读取文件行数
*
*@parampath
*文件路径
*@returnlong
*/
publicstaticlongreadLine(Stringpath){
longindex=0;
try{
RandomAccessFilefile=newRandomAccessFile(newFile(path),"r");
while(null!=file.readLine()){
index++;
}
file.close();
}catch(Exceptione){
e.printStackTrace();
}
returnindex;
}
}
4. java中怎么获得一个文本文件的行数
涉及到java中读写文件的IO操作。
获取一个文本文件的行数较为方便的方法,是通过BufferedReader类的readLine()方法,间接的统计行数。
源代码:
public
static
int
getTextLines()
throws
IOException
{
String
path
=
"c:\\job.txt"
;//
定义文件路径
FileReader
fr
=
new
FileReader(path);
//这里定义一个字符流的输入流的节点流,用于读取文件(一个字符一个字符的读取)
BufferedReader
br
=
new
BufferedReader(fr);
//
在定义好的流基础上套接一个处理流,用于更加效率的读取文件(一行一行的读取)
int
x
=
0;
//
用于统计行数,从0开始
while(br.readLine()
!=
null)
{
//
readLine()方法是按行读的,返回值是这行的内容
x++;
//
每读一行,则变量x累加1
}
return
x;
//返回总的行数
}
5. java IO流读文件能不能得到行数
理论上说是不能直接得到的,因为最原始的IO流是字节流也就是说一次只能读到一个字节的数据,这里面根本就没有行数之说;此外,即使使用缓冲流最多也就是每次读进一行已,如果想要得到文件的行数就得等文件读完才知道。
6. java 项目 代码行数多少 算大项目
java项目的大小衡量标准:
微型:只是一个人,甚至是半日工作在几天内完成的软件;
小型:一个人半年内完成的2000行以内的程序;
中型:5个人在1年多的时间内完成的5000-50000行的程序;
大型:5-10人在两年内完成的50000-100000行的程序;
甚大型:100-1000人参加用4-5年完成的具有100,0000行的软件项目;
极大型:2000-5000人参加,10年内完成的1000万行以内的程序;
以上摘自:《软件工程概论》郑人杰、殷人民编
这样的观点是以代码行作为计量标准的,认为代码行多的自然项目也就大了。
7. 一个java文件里面最多写多少行代码
1,java规范中一般不建议一个java类中超过500行
2,一行的长度不超过200个
3,按照规定格式将代码格式化
8. Java 有什么好的代码行数,注释行数统计工具
package com.syl.demo.test;
import java.io.*;
/**
* java代码行数统计工具类
* Created by 孙义朗 on 2017/11/17 0017.
*/
public class CountCodeLineUtil {
private static int normalLines = 0; //有效程序行数
private static int whiteLines = 0; //空白行数
private static int commentLines = 0; //注释行数
public static void countCodeLine(File file) {
System.out.println("代码行数统计:" + file.getAbsolutePath());
if (file.exists()) {
try {
scanFile(file);
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("文件不存在!");
System.exit(0);
}
System.out.println(file.getAbsolutePath() + " ,java文件统计:" +
"总有效代码行数: " + normalLines +
" ,总空白行数:" + whiteLines +
" ,总注释行数:" + commentLines +
" ,总行数:" + (normalLines + whiteLines + commentLines));
}
private static void scanFile(File file) throws IOException {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
scanFile(files[i]);
}
}
if (file.isFile()) {
if (file.getName().endsWith(".java")) {
count(file);
}
}
}
private static void count(File file) {
BufferedReader br = null;
// 判断此行是否为注释行
boolean comment = false;
int temp_whiteLines = 0;
int temp_commentLines = 0;
int temp_normalLines = 0;
try {
br = new BufferedReader(new FileReader(file));
String line = "";
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.matches("^[//s&&[^//n]]*$")) {
// 空行
whiteLines++;
temp_whiteLines++;
} else if (line.startsWith("/*") && !line.endsWith("*/")) {
// 判断此行为"/*"开头的注释行
commentLines++;
comment = true;
} else if (comment == true && !line.endsWith("*/")) {
// 为多行注释中的一行(不是开头和结尾)
commentLines++;
temp_commentLines++;
} else if (comment == true && line.endsWith("*/")) {
// 为多行注释的结束行
commentLines++;
temp_commentLines++;
comment = false;
} else if (line.startsWith("//")) {
// 单行注释行
commentLines++;
temp_commentLines++;
} else {
// 正常代码行
normalLines++;
temp_normalLines++;
}
}
System.out.println(file.getName() +
" ,有效行数" + temp_normalLines +
" ,空白行数" + temp_whiteLines +
" ,注释行数" + temp_commentLines +
" ,总行数" + (temp_normalLines + temp_whiteLines + temp_commentLines));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
br = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
//测试
public static void main(String[] args) {
File file = new File("F:\\myweb");
countCodeLine(file);
}
}
9. 如何统计输入内容的行数,java
如果是读入文件统计行数,用readline,每读一行,计数加1
如果是在控制台输入,每行做为一个字符串,用endwith判断是否以
换行符
结尾,true加1
10. 用java编写 统计文件中的字符数 单词数和行数
在C盘新建文件1.txt,输入任意字符,如下图: