package 遍历文件夹里面的文件;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class BianLi {
public static void main(String[] args) throws IOException {
File a=new File("d:\\123");
BianLi(a);
}
public static void BianLi(File file) throws IOException{
File[] arr=file.listFiles();
for(File i:arr){
if(i.isFile()){
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(i));
byte[] bys=new byte[1024];
int ch=0;
while((ch=bis.read(bys))!=-1){
System.out.println(new String(bys,0,ch));
}
bis.close();
}else{
BianLi(i);
}
}
}
}
自定义一个方法就可以。主函数进行调用
|