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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Java File类void deleteOnExit()方法(带示例)

發(fā)布時(shí)間:2023/12/1 java 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java File类void deleteOnExit()方法(带示例) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文件類void deleteOnExit() (File Class void deleteOnExit())

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

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

  • This method is used to delete the file or directory when the virtual machine terminates.

    虛擬機(jī)終止時(shí),此方法用于刪除文件或目錄。

  • The return type of this method is void so it does not return anything.

    此方法的返回類型為void,因此它不返回任何內(nèi)容。

  • In this method delete file or directories in the reverse order, that means last created file or directories will be deleted first when virtual machine terminates.

    在此方法中,以相反的順序刪除文件或目錄,這意味著在虛擬機(jī)終止時(shí),將首先刪除最后創(chuàng)建的文件或目錄。

  • This method may raise an exception (i.e. Security Exception) delete access is not given to the file.

    此方法可能會(huì)引發(fā)異常(即Security Exception),但未授予該文件訪問權(quán)限。

Syntax:

句法:

void deleteOnExit(){}

Parameter(s):

參數(shù):

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

我們不會(huì)在File方法中將任何對(duì)象作為參數(shù)傳遞。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回類型為void ,它不返回任何內(nèi)容。

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

// import the File class because we will use File class methods import java.io.File;// import the Exception class because it may raise an // exception when working with files import java.lang.Exception;class DeleteFileOnExit {public static void main(String[] args) {try {// Specify the path of file and we use double slashes to // escape '\' character sequence for windows otherwise // it will be considerable as url.File file1 = new File("C:\\Users\\computer clinic\\OneDrive\\Articles\\myjava.txt");// By using getAbsolutePath() return the complete // path of the fileString abs_path = file1.getAbsolutePath();// Display absolute path of the file object System.out.println("The absolute path of the file 1 if given path is absolute :" + " " + abs_path);// By using deleteOnExit() method to delete the file // when the virtual machine terminatesfile1.deleteOnExit();System.out.println("This file will delete as soon as the virtual machine terminates");} catch (Exception e) {System.out.println("An error occurred.");e.printStackTrace();}} }

Output

輸出量

E:\Programs>javac DeleteFileOnExit.javaE:\Programs>java DeleteFileOnExit The absolute path of the file 1 if given path is absolute : C:\Users\computer clinic\OneDrive\Articles\myjava.txt This file will delete as soon as the virtual machine terminates

翻譯自: https://www.includehelp.com/java/file-class-void-deleteonexit-method-with-example.aspx

總結(jié)

以上是生活随笔為你收集整理的Java File类void deleteOnExit()方法(带示例)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。