File類中的方法實現
阿新 • • 發佈:2019-02-15
public class File { public static void main(String[] args) { File file = new File("E:\\kankan\\XMPCache"); File absoluteFile = file.getAbsoluteFile(); System.out.println("getAbsoluteFile:" + absoluteFile); String AbsPath = file.getAbsolutePath(); System.out.println("getAbsolutePath:" + AbsPath); String path = file.getPath(); System.out.println("getPath:" + path); File parentFile = file.getParentFile(); File parentFile1 = parentFile.getParentFile(); System.out.println("父類檔案parentFile:" + parentFile); System.out.println("父類的父類檔案parentFile1:" + parentFile1); File[] files = file.listFiles(); System.out.println("============="); for (File f: files) { System.out.println("listFiles:" + f.getName()); System.out.println("是否是隱藏檔案:" + f.isHidden()); System.out.println("是否是絕對路徑名:" + f.isAbsolute()); } System.out.println("=============="); File[] root = file.listRoots(); for (File f : root) { System.out.println("listRoots:" + f); System.out.println("listRoots:" + f.getName()); } System.out.println("==========="); } }