java 读取目录下所有文件名以及文件内容 要求是先输出文件名,然后换行输出文件内容
展开全部
String url = "D:\\aa";
File file = new File(url);
if(file.isDirectory()) {
String[] s = file.list();
int l = s.length;
for(int i=0;i<l;i++) {
System.out.println(s[i]);
File f = new File(url+"\\"+s[i]);
if(!f.isDirectory()) {
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
}
}
}
File file = new File(url);
if(file.isDirectory()) {
String[] s = file.list();
int l = s.length;
for(int i=0;i<l;i++) {
System.out.println(s[i]);
File f = new File(url+"\\"+s[i]);
if(!f.isDirectory()) {
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println(sb.toString());
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询