码迷,mamicode.com
首页 > 其他好文 > 详细

File类的获取功能

时间:2016-04-15 15:22:19      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

File类的获取功能

标签:

原文地址:http://www.cnblogs.com/msirene/p/5395556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!