package DAYTWO;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class 输出写了多少行代码 {
public static int sum=0;
public static void main(String[] args) {
ss11("F:\\JAVA\\new folder2");
BufferedWriter bf=null;
try {
bf = new BufferedWriter(new FileWriter("写了多少行代码.txt",true));
} catch (Exception e) {
e.printStackTrace();
}
String valueOf = String.valueOf(sum);
SimpleDateFormat bartDateFormat =new SimpleDateFormat("yyyy年MM月dd日HH时mm分--EEEE");
Date date = new Date();
String str21=bartDateFormat.format(date).toString();
try {
bf.write(str21+"-----"+valueOf+"行");
bf.newLine();
} catch (Exception e) {
e.printStackTrace();
}
try {
bf.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(sum);
}
public static void ss11(String str){
File file = new File(str);
File[] listFiles = file.listFiles();
BufferedReader br=null;
if(listFiles!=null){
for (File file2 : listFiles) {
if(file2.isFile()&&file2.getName().endsWith(".java")){
try {
br= new BufferedReader(new FileReader(file2));
String len;
try {
while((len=br.readLine())!=null){
sum++;
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
if(file2.isDirectory()){
ss11(file2.getAbsolutePath());
}
}
if(br!=null){
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}