黑马程序员技术交流社区
标题:
File 的获取功能
[打印本页]
作者:
朱吕龙
时间:
2015-5-31 22:20
标题:
File 的获取功能
获取功能:
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));
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2