參考資料:
http://ced425.pixnet.net/blog/post/3368206-java.io.file%E9%A1%9E%E7%B7%B4%E7%BF%92
import java.io.*;
public class File_Print{
public static void main(String args[]){
File f = new File("c:\\Documents");
System.out.print("Directory Name: "+f.getName()+"\n");
print(f,1);
}
private static void print(File f, int level){
String pl = "";
for(int i = 0 ; i < level ; i++){
pl +="\t";
}
File[] child = f.listFiles();
for(int i = 0; i < child.length ; i++){
String s = child[i].getName();
System.out.println(pl+" ("+s+")");
if(s.equals("a.java")){
File fc = child[i];
File toFile = new File("C:\\Documents\\abcd"+"\\"+"child[i].getName()");
fc.renameTo(toFile);
System.out.println("-------------------------------------------------");
}
if(child[i].isDirectory()){
System.out.print("*");
print(child[i], level+1);
}
}
}
}
沒有留言:
張貼留言