A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 朱吕龙 中级黑马   /  2015-5-31 22:20  /  433 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

获取功能:
  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));
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马