import java.io.*;public class Counter {
private int files = 0;
private int size=0;
private int count = 0;
private int rem = 0;
private int code = 0;
private int empty = 0; public Counter(File f) {
count(f);
} private void count(File f) {
if (f.isFile()) {
countFile(f);
}
else {
File[] list = f.listFiles();
for (int i = 0; i < list.length; i++) {
count(list[i]);
}
}
} private void countFile(File f) {
if (f.getName().toLowerCase().endsWith(".java")) {
files++;
size+=f.length();
try {
BufferedReader br = new BufferedReader(new FileReader(f));
String s = null;
boolean isrem = false;
int k1,k2,k3,k4;
while ( (s = br.readLine()) != null) {
s = s.trim();
count++;
if(s.length()==0){
empty++;
continue;
}
k1=s.indexOf("/*");
k2=s.lastIndexOf("*/");
k3=s.indexOf("//");
if(isrem){
if(k2!=-1){
isrem=false;
if(k2!=s.length()-1){
code++;
}
}
rem++;
}
else{
if(k1==0){
isrem=true;
rem++;
continue;
}
else if(k1>0){
isrem=true;
rem++;
code++;
continue;
}
if(k3==0){
rem++;
continue;
}
else if(k3>0){
rem++;
code++;
continue;
}
code++;
}
}
}
catch (Exception ex) {ex.printStackTrace();}
}
} public static void main(String[] args) {
File f = new File(
"D:\\李劲\\ccats\\java\\src\\com\\ccats\\help");
Counter c = new Counter(f);
System.out.println("File :" + c.getFiles());
System.out.println("Size :" + c.getSize());
System.out.println("Count :" + c.getCount());
System.out.println("Rem :" + c.getRem());
System.out.println("Code :" + c.getCode());
System.out.println("Empty :" + c.getEmpty());
} public int getCode() {
return code;
} public int getCount() {
return count;
} public int getRem() {
return rem;
} public int getFiles() {
return files;
} public int getEmpty() {
return empty;
}
public int getSize() {
return size;
}}
自己修改吧
private int files = 0;
private int size=0;
private int count = 0;
private int rem = 0;
private int code = 0;
private int empty = 0; public Counter(File f) {
count(f);
} private void count(File f) {
if (f.isFile()) {
countFile(f);
}
else {
File[] list = f.listFiles();
for (int i = 0; i < list.length; i++) {
count(list[i]);
}
}
} private void countFile(File f) {
if (f.getName().toLowerCase().endsWith(".java")) {
files++;
size+=f.length();
try {
BufferedReader br = new BufferedReader(new FileReader(f));
String s = null;
boolean isrem = false;
int k1,k2,k3,k4;
while ( (s = br.readLine()) != null) {
s = s.trim();
count++;
if(s.length()==0){
empty++;
continue;
}
k1=s.indexOf("/*");
k2=s.lastIndexOf("*/");
k3=s.indexOf("//");
if(isrem){
if(k2!=-1){
isrem=false;
if(k2!=s.length()-1){
code++;
}
}
rem++;
}
else{
if(k1==0){
isrem=true;
rem++;
continue;
}
else if(k1>0){
isrem=true;
rem++;
code++;
continue;
}
if(k3==0){
rem++;
continue;
}
else if(k3>0){
rem++;
code++;
continue;
}
code++;
}
}
}
catch (Exception ex) {ex.printStackTrace();}
}
} public static void main(String[] args) {
File f = new File(
"D:\\李劲\\ccats\\java\\src\\com\\ccats\\help");
Counter c = new Counter(f);
System.out.println("File :" + c.getFiles());
System.out.println("Size :" + c.getSize());
System.out.println("Count :" + c.getCount());
System.out.println("Rem :" + c.getRem());
System.out.println("Code :" + c.getCode());
System.out.println("Empty :" + c.getEmpty());
} public int getCode() {
return code;
} public int getCount() {
return count;
} public int getRem() {
return rem;
} public int getFiles() {
return files;
} public int getEmpty() {
return empty;
}
public int getSize() {
return size;
}}
自己修改吧
解决方案 »
- jsp访问action
- 问个json类型转换的问题
- struts2下载 没有弹出框 并报js错误
- mybatis如何实现有继承关系的类的插入?
- 【JDBC问题】如何以DBA身份连接oracle
- CMP EntityBean如何实现对某字段的统计?象SQL中的select count(*) from .....
- 谁还记得,我忘了:)
- 关于websphere应用服务器的问题,(我知道应该在IBM专区问,可那里没人回答)。
- 水晶报表接口, No SAX parser is available问题
- easiui中centre中的页面无法加载js文件。
- xml中bean调用问题
- 哪位帅哥或MM讲下JBuilder下的Struts的开发过程吗?谢谢~~~
对了,再问一下,在这里怎么结分啊?
根据命令行参数不同,可以分别得到下面两种输出:
1. 纯文本输出。
2. HTML表格输出。
具体输出的格式由程序员从用户角度考虑,自行设计。
其他要求
1. 易于扩充:程序未来可能需要扩充,比如其他输出格式。还有人能帮忙解决一下吗, 这个做不出来。