获取功能:
String getAbsolutePath():绝对路径
String getPath():相对路径
String getName():文件名称
long length():文件大小,单位是字节
long lastModified():上次修改时间的毫秒值。
public class FileDemo {
public static void main(String[] args) {
// 需求:指向文件
File file = new File("bbb\\ccc\\a.txt");
System.out.println("getAbsolutePath:" + file.getAbsolutePath());
System.out.println("getPath:" + file.getPath());
System.out.println("getName:" + file.getName());
System.out.println("length:" + file.length());
System.out.println("lastModified:" + file.lastModified());
Date d = new Date(file.lastModified());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(d));
}
} |
|