
正文
显示java代码行数 java怎么显示代码行数
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
android studio 怎么查看工程总代码行数
其实原理就是识别整个项目工程中的换行有几个也就是\n:
android studio统计项目的代码行数的步骤如下:
1)按住Ctrl+Shift+A,在弹出的框输入‘find’,然后选择Find in Path.(或者使用快捷键Ctrl+Shift+F)
2)在弹出Find in Path的框中的Text to find输入\n,接着勾选Regular expression(正则表达式),Context选择anywhere,
Scope根据你想要统计的范围进行选择,File mask选择*.java。(在这里统计项目的Java的代码行数)
3)下图的Useages in generated code是自动生成的代码,上面那个就是项目的代码行数。
相关问答
Q1: 如何计算一个.java文件的代码行数
方法一:
如果想要通过java代码的方式来计算.java文件的行数,可以通过IO来读取,
BufferedReader的方法readLine()来按行读取,每读取一行,行数+1
方法二:
如果要查看.java文件的代码行数, 可以使用现成的IDE工具,比如ECLIPSE...
每一行的行号都有表示出来
Q2: 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; //返回总的行数
}
相信看完上面的,应该就会了。
Q3: 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("*/")) {
// 判断此行为"/*"开头显示java代码行数的注释行
commentLines++;
comment = true;
} else if (comment == true !line.endsWith("*/")) {
// 为多行注释中显示java代码行数的一行(不是开头和结尾)
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);
}
}
Q4: eclipse怎么统计代码行数
Eclipse可以方便的统计工程或文件的代码行数。方法如下:
1.首先选中你要统计的工程,在菜单栏点击Search,然后点击File...
2.选中右侧正则表达式(Regular expression),并在搜索文本框输入\n
3.在文件名中输入*或*.java
4.在范围里选中Enclosing projects
5.在Search窗口就会显示出项目或文件的代码行数
Q5: java eclipse如何显示行数
问题1:在编辑区最左边地方右键显示java代码行数,选择“Show Line Numbers”就行显示java代码行数了。
问题2:快捷键(ctrl+f)
问题3:在工程名上右键,选择“Refactor-Rename”。
希望对你有帮助显示java代码行数!
关于显示java代码行数和java怎么显示代码行数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






