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.
此方法用于設(shè)置給定文件的最后修改時(shí)間。
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.
換句話說,如果文件存在,則每個(gè)文件都有最后修改時(shí)間,但是通過使用此方法,我們可以使用給定的新時(shí)間來更改文件的最后修改時(shí)間。
The return type of this method is Boolean so it returns true if file last modification is set successfully else return false.
此方法的返回類型為Boolean,因此如果成功設(shè)置了文件上次修改,則返回true,否則返回false。
Syntax:
句法:
boolean setLastModified(long set_new_time){}Parameter(s):
參數(shù):
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).
在文件方法中,我們僅傳遞一個(gè)對象作為參數(shù),即set_new_time (我們將新時(shí)間設(shè)置為文件的最后修改時(shí)間)。
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 ,如果成功設(shè)置了文件的上一次修改的給定時(shí)間,則返回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
總結(jié)
以上是生活随笔為你收集整理的Java文件类boolean setLastModified(long set_new_time)方法,包含示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java calendar_Java C
- 下一篇: Android ImageButton示