1 import java.io.File;
2 import java.text.SimpleDateFormat;
3 import java.util.Date;
4
5 /*
6 * 获取功能:
7 * public String getAbsolutePath():获取绝对路径
8 * public String getPath():获取相对路径
9 * public String getName():获取名称
10 * public long length():获取长度。字节数
11 * public long lastModified():获取最后一次的修改时间,毫秒值
12 */
13 public class FileDemo {
14 public static void main(String[] args) {
15 // 创建文件对象
16 File file = new File("demo\\test.txt");
17
18 System.out.println("getAbsolutePath:" + file.getAbsolutePath());
19 System.out.println("getPath:" + file.getPath());
20 System.out.println("getName:" + file.getName());
21 System.out.println("length:" + file.length());
22 System.out.println("lastModified:" + file.lastModified());
23
24 // 1460703654874
25 Date d = new Date(1460703654874L);
26 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
27 String s = sdf.format(d);
28 System.out.println(s);
29 }
30 }