lastmodified_Java文件类long lastModified()方法(带示例)

lastmodified

文件类long lastModified() (File Class long lastModified())

  • This method is available in package java.io.File.lastModified().

    软件包java.io.File.lastModified()中提供了此方法。

  • This method is used to return the time when the file is last modified.

    此方法用于返回上次修改文件的时间。

  • In other words, this method indicates the work by its name it returns the last modification time of the file and time will be measurable in milliseconds.

    换句话说,此方法以名称表示工作,它返回文件的最后修改时间,该时间可以毫秒为单位。

  • The return type of this method is long so it returns the last modified time of the file and else returns 0L if the file does not exist or an exception occurs.

    此方法的返回类型很长,因此它返回文件的最后修改时间,如果文件不存在或发生异常,则返回0L

Syntax:

句法:

    long lastModified(){
    }

Parameter(s):

参数:

We don't pass any object as a parameter in the method of the File.

我们不会在File方法中将任何对象作为参数传递。

Return value:

返回值:

The return type of this method is long, it returns the time in milliseconds else return 0L if any exception occurs or file does not exist.

此方法的返回类型为long ,它返回时间(以毫秒为单位),如果发生任何异常或文件不存在,则返回0L。

Java程序演示lastModified()方法的示例 (Java program to demonstrate example of lastModified() method)

import java.io.*;

public class FileLastModifiedTime {
    public static void main(String[] args) {
        try {
            // Create a file object file1
            File file1 = new File("E:\\Programs\\myjava.txt");

            // Create a file object file2
            File file2 = new File("C:\\Users\\computerclinic\\OneDrive\\Articles\\myjava1.txt");

            // By using lastModified() method return the time 
            // when the file1 is last modified.
            System.out.println("The Last Modification Time Of File1 is : " + file1.lastModified());

            // By using lastModified() method return 0L because 
            // the file2 does not exists.
            System.out.println("The Last Modification Time Of File2 is : " + file2.lastModified());
        } catch (Exception e) {
            System.err.println("An error occurred");
            e.printStackTrace();
        }
    }
}

Output

输出量

E:\Programs>javac FileLastModifiedTime.java

E:\Programs>java FileLastModifiedTime
The Last Modification Time Of File1 is : 1563132418281
The Last Modification Time Of File2 is : 0


翻译自: https://www.includehelp.com/java/file-class-long-lastmodified-method-with-example.aspx

lastmodified

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值