package com;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Text {
public static void main(String[] args) {
File file = new File("E:\\rrr");//读取文件的文件夹目录
opervate(file);
}
public static void opervate(File file){
try {
File[] fi = file.listFiles();//获取文件夹下的子目录
for (int i = 0; i < fi.length; i++) {//循环
File f = fi[i];
if(f.isDirectory()){
opervate(f);
}else{
if(f.getName().endsWith("txt")){//获取后缀txt文件
FileInputStream a = new FileInputStream(f);//拿到f里面的内容
byte[] by = new byte[(int)(f.length())];//创建byte字节输出(int)类型,byte的长度=内容的长度
a.read(by);//读取内容
String str = new String(by);//转换为String 因为文件是由字节流传输。
System.out.println(str);
}
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}