package com.jzm.io;
import java.io.File;
public class FileDemo {
static void p(String s){
System.out.println(s);
}
public static void main(String[] args) {
File f1 = new File("d:/java/copyright/test.txt"); //指定文件位置
p("File name= "+f1.getName());
p("Path: "+f1.getPath());
p("abs path: "+f1.getAbsolutePath());
p("Parent: "+ f1.getParent());
p(f1.exists()? "exists" : "does not exist");
p(f1.canWrite()? "is writeabale" : "is not writeable");
p("File size: "+f1.length());
p(f1.isDirectory()?"is directory" : "not directory");
p(f1.isFile()? "is a file":"is not a file");
}
}
输出结果为:
File name= test.txt
Path: c:\java\copyright\test.txt
abs path: c:\java\copyright\test.txt
Parent: c:\java\copyright
does not exist
is not writeable
File size: 0
not directory
is not a file