把E盘下的所有.java文件写到F盘的文件夹里
public class FileDemo3 {
public static void main(String[] args) throws Exception {
File file = new File("E:\\");
File file1 =new File("F:\\javaFile");
FileWriter fw = new FileWriter(file1);
getFile(file ,fw);
}
public static void getFile(File file,FileWriter fw) throws Exception{
File[] file2 = file.listFiles();
for(File f:file2){
if(f.isDirectory()){
getFile(f,fw);
}else{
if(f.getName().endsWith(".txt")){
FileReader fr = new FileReader(f);
char[] ch = new char[1024];
int len = 0;
while((len=fr.read(ch))!=-1){
fw.write(ch, 0, len);
fw.flush();
}
}
}
}
}
}
F盘拒绝访问,怎么改 |
|