文件属性(常用)
public String getName(); | 获取文件名字 |
---|---|
public long length(); | 获取文件的长度(以字节为单位) |
public boolean exits(); | 文件是否存在 |
public long length(); | 获取文件的长度(以字节为单位) |
public long lastModified(); | 获取文件最后修改时间 |
public boolean isFile(); | 判断是文件还是目录 |
public String getPath(); | 获取文件输入的路径 |
For example:
import java.io.File;
public class File_Common_Properties {
public static void main(String[] args) {
File f=new File("file.txt");
System.out.println(f.getName()+"是可以读文件?:"+f.canRead());
System.out.println(f.getName()+"的长度:"+f.length());
System.out.println(f.getName()+"的路径:"+f.getPath());
System.out.println(f.getName()+"是否存在:"+f.exists());
}
}
Result:
其它属性:
public String getParent(); | 获取文件的父目录 |
---|---|
public String getAbsolutePath(); | 获取文件绝对路径 |
public boolean canRead(); | 判断文件的可读性 |
public boolean canWrite(); | 判断文件的可写性 |
public boolean isHidden(); | 判断文件是否是隐藏文件 |