Io
知识点:没啥,主要是应用,然后把这张图片弄懂
public static void main(String[] args) throws ParseException, IOException {public class Pricatice {
static int sum = 0;
// Scanner sc = new Scanner(System.in);
// System.out.println("请输入你的身份证号:");
// String idcard = sc.next();
// String sd = "";// 先搞一个空的字符串留着
// Long start = new Date().getTime();//当前时间
// Date d = null;
// int day = 0;
// String sfz =
// "(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$)";//regex掌握即可
// if ((idcard.length() == 15 || idcard.length() == 18) && idcard.matches(sfz))
// {
// if (idcard.length() == 15) {
// sd = idcard.substring(6, 12);
// SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
// d = sdf.parse(sd);//String——>Date
// day = (int) ((start - d.getTime()) / 1000 / 60 / 60 / 24);
// } else if (idcard.length() == 18) {
// sd = idcard.substring(6, 14);
// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
// d = sdf.parse(sd);
// day = (int) ((start - d.getTime()) / 1000 / 60 / 60 / 24);
// }
// } else {
// System.out.println("输入有误!");
// }
// }
// System.out.println("你已经活了"+day);
// sc.close();
// File f = new File("c:/自我介绍.txt");
// if (!f.exists()) {
// f.createNewFile();
// }
// PrintWriter pw = new PrintWriter(f);
// pw.println("姓名:张三");
// pw.println("年龄:20");
// pw.println("地址:河南郑州金水区");
// pw.close();
// BufferedReader br = new BufferedReader(new FileReader(f));//这个流为哈不是new BufferedReader(new FileReader(new File()))得想想?????????????????
// while ((s = br.readLine()) != null) {
// System.out.println(s);
// }
// br.close();
Zy.readFile(new File("E:class/javaSE"));
System.out.println(sum);
}
//判断自己写了多少行代码?
public static void readFile(File f) throws IOException {
// 先判断文件是否存在
if (f.exists()) {
// 判断是否是目录
if (f.isDirectory()) {
// 得到所有的子文件
File[] fs = f.listFiles();
if (fs != null && fs.length > 0) {
for (File ff : fs) {
// 递归调用,这个递归必须要掌握哦
readFile(ff);
}
}
} else {
if (f.getName().endsWith(".java")) {
BufferedReader br = new BufferedReader(new FileReader(f));
String s = "";
while ((s = br.readLine()) != null) {
if (s.contains("import") || s.contains("//") || s.contains("package")
|| s.contains("/*") || s.startsWith("*")) {
continue;
}
sum++;
}
br.close();
}
}
}
}
}