package com.abin.lee.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class FileTotal {
public static void ReadSubdirectory(File dir){
if(dir.isDirectory()){
File[] subFile=dir.listFiles();
for(int i=0;i<subFile.length;i++){
if(subFile[i].isDirectory()){
ReadSubdirectory(subFile[i]);
}else{
ReadSubFile(subFile[i]);
}
}
}
}
public static void ReadSubFile(File file){
int numCount=0;
int letterCount=0;
int spaceCount=0;
int lineCount=0;
int temp=0;
try {
FileInputStream input=new FileInputStream(file);
while((temp=input.read())!=-1){
if(temp>=48&&temp<=57){
numCount++;
}else if((temp>=65&&temp<=90)||(temp>97&&temp<122)){
letterCount++;
}else if(temp==32){
spaceCount++;
}
}
BufferedReader buffer=new BufferedReader(new InputStreamReader(new FileInputStream(file)));
while(buffer.readLine()!=null){
lineCount++;
}
System.out.println("文件路径:"+file.getAbsolutePath());
System.out.println("数字个数:"+numCount);
System.out.println("字母个数:"+letterCount);
System.out.println("空格个数:"+spaceCount);
System.out.println("行数数:"+lineCount);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
ReadSubdirectory(new File("D://image"));
}
}