日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java文件类boolean setLastModified(long set_new_time)方法,包含示例

發布時間:2025/3/11 java 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java文件类boolean setLastModified(long set_new_time)方法,包含示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文件類boolean setLastModified(long set_new_time) (File Class boolean setLastModified(long set_new_time))

  • This method is available in package java.io.File.setLastModified(long set_new_time).

    軟件包java.io.File.setLastModified(long set_new_time)中提供了此方法。

  • This method is used to sets the last modified time of the given file.

    此方法用于設置給定文件的最后修改時間。

  • In other words, Every file has some last modified time if file exists but by using this method we can change the last modified time of the file with the given new time.

    換句話說,如果文件存在,則每個文件都有最后修改時間,但是通過使用此方法,我們可以使用給定的新時間來更改文件的最后修改時間。

  • The return type of this method is Boolean so it returns true if file last modification is set successfully else return false.

    此方法的返回類型為Boolean,因此如果成功設置了文件上次修改,則返回true,否則返回false。

Syntax:

句法:

boolean setLastModified(long set_new_time){}

Parameter(s):

參數:

We pass only one object as a parameter in the method of the file i.e. set_new_time (We will set new time as last modified time of the file).

在文件方法中,我們僅傳遞一個對象作為參數,即set_new_time (我們將新時間設置為文件的最后修改時間)。

Return value:

返回值:

The return type of this method is Boolean, it returns true if the given time is set successfully of last modification of the file else it returns false.

此方法的返回類型為Boolean ,如果成功設置了文件的上一次修改的給定時間,則返回true ,否則返回false 。

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

import java.io.*;public class SetFileLastModifiedTime {public static void main(String[] args) {try {// Create a file object file1File file1 = new File("E:\\Programs\\myjava.txt");// Previous Last Modified Time Of The File1System.out.println("The Previous Last Modification Time Of File1 is : " + file1.lastModified());// By using setLastModified(long set_new_time) method sets // new last modified time of the file.System.out.println("The New Last Modification Time has set : " + file1.setLastModified(2000000));// Display New Last Modified Time Of The File1System.out.println("The New Last Modification Time Of File1 is : " + file1.lastModified());} catch (Exception e) {System.err.println("An error occurred");e.printStackTrace();}} }

Output

輸出量

E:\Programs>javac SetFileLastModifiedTime.javaE:\Programs>java SetFileLastModifiedTime The Previous Last Modification Time Of File1 is : 1000000 The New Last Modification Time Of File1 has set : true The New Last Modification Time Of File1 is : 2000000

翻譯自: https://www.includehelp.com/java/file-class-boolean-setlastmodified-long-set_new_time-method-with-example.aspx

總結

以上是生活随笔為你收集整理的Java文件类boolean setLastModified(long set_new_time)方法,包含示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。