import java.io.File; public class Test { public static void main(String[] args) { MakeDirectories.test(); } } class MakeDirectories { //用于展示File对象各种信息 private static void fileData(File file) { StringBuilder sb = new StringBuilder(); sb.append("\nAbsolute path:"+ file.getAbsolutePath()); sb.append("\n Can Read:"+ file.canRead()); sb.append("\n Can Write:"+ file.canWrite()); sb.append("\n Get Name:"+ file.getName()); sb.append("\n Get Parent:"+ file.getParent()); sb.append("\n Get Path:"+ file.getPath()); sb.append("\n Length:"+ file.length()); sb.append("\n LastModified:"+ file.lastModified()); sb.append("\n Is File:"+ file.isFile()); sb.append("\n Is Directory:"+ file.isDirectory()); System.out.println(sb.toString()); } //用于测试rename方法 private static void rename(String file1,String file2) { File o = new File(file1); File n = new File(file2); o.renameTo(n); } // private static void deleteandmkdirs(String file) { File f = new File(file); //文件存在,则删除 if (f.exists()) { f.delete(); } //文件不存在,则创建 else { f.mkdirs(); } } public static void test() { //File f = new File("."); //fileData(f); // String file1="./file1"; // String file2="./file2"; // //File f1 = new File(file1); // //File f2 = new File(file2); // rename(file1,file2); // File f1 = new File(file1); // File f2 = new File(file2); // fileData(f1); // fileData(f2); } }