Java File類void deleteOnExit()方法(帶示例)

文件類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.

    虛擬機終止時,此方法用于刪除文件或目錄。

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

    此方法的返回類型為void,因此它不返回任何內容。

  • 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.

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

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

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

Syntax:

句法:

    void deleteOnExit(){
}

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 void, it does not return anything.

此方法的返回類型為void ,它不返回任何內容。

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 file
String 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 terminates
file1.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.java
E:\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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379738.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379738.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379738.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

FreeRTOS隊列

在實際應用中,我們會遇到一個任務或者中斷服務需要和另一個任務進行消息傳遞,FreeRTOS提供了隊列的機制來完成任務與任務、任務與中斷之間的消息傳遞。 0x01 隊列簡介 隊列是為了任務與任務、任務與中斷之間的通信而準備的,可以在任務與任務…

括號配對問題(C)

描述 現在&#xff0c;有一行括號序列&#xff0c;請你檢查這行括號是否配對。 輸入 第一行輸入一個數N&#xff08;0<N<100&#xff09;,表示有N組測試數據。后面的N行輸入多組輸入數據&#xff0c;每組輸入數據都是一個字符串S(S的長度小于10000&#xff0c;且S不是空串…

劇情介紹:“阿甘正傳”

阿甘是個智商只有75的低能兒。在學校里為了躲避別的孩子的欺侮&#xff0c;聽從一個朋友珍妮的話而開始“跑”。他跑著躲避別人的捉弄。在中學時&#xff0c;他為了躲避別人而跑進了一所學校的橄欖球場&#xff0c;就這樣跑進了大學。阿甘被破格錄取&#xff0c;并成了橄欖球巨…

java 方法 示例_Java集合syncedList()方法與示例

java 方法 示例集合類syncList()方法 (Collections Class synchronizedList() method) synchronizedList() method is available in java.util package. syncList()方法在java.util包中可用。 synchronizedList() method is used to return the synchronized view of the given…

FreeRTOS信號量---二值信號量

信號量可以用來進行資源管理和任務同步&#xff0c;FreeRTOS中信號量又分為二值信號量、計算型信號量、互斥信號量和遞歸互斥信號量。 0x01 二值信號量 二值信號量其實就是一個只有一個隊列項的隊列&#xff0c;這個特殊的隊列要么是滿的&#xff0c;要么是空的&#xff0c;任…

Linux 上 rpm包管理工具的基本使用

查詢是否安裝某個包&#xff1a;rpm -q 包名查詢所有已安裝的包&#xff1a;rpm -q a查詢未安裝包的文件信息&#xff1a;rpm -qilp 未安裝的包安裝包&#xff1a;rpm -i 包測試安裝包&#xff1a;rpm -i test 包刪除包&#xff1a;rpm -e 包名測試刪除包&#xff1a;rpm -e te…

ios 內存使用陷阱

在iphone開發過程中&#xff0c;代碼中的內存泄露我們很容易用內存檢測工具leaks 檢測出來&#xff0c;并一一改之&#xff0c;但有些是因為ios 的缺陷和用法上的錯誤&#xff0c;leaks 檢測工具并不能檢測出來&#xff0c;你只會看到大量的內存被使用&#xff0c;最后收到didR…

FreeRTOS軟件定時器

軟件定時器允許設置一段時間&#xff0c;當設置的時間達到后就執行指定的功能函數&#xff0c;被軟件定時器調用的功能函數叫做定時器的回調函數。軟件定時器的回調函數是在定時器服務任務中執行的&#xff0c;所以一定不能在回調函數中調用任何阻塞任務的API函數&#xff0c;比…

Java類class isAssignableFrom()方法及示例

類class isAssignableFrom()方法 (Class class isAssignableFrom() method) isAssignableFrom() method is available in java.lang package. isAssignableFrom()方法在java.lang包中可用。 isAssignableFrom() method is used to check whether the class or an interface den…

關于 列表實例

wss3.0工具中有個列表實例項目。此項目的作用是在自定義網站或自定義字段時使用默認值。也就是定義其默認的數據。 格式詳見微軟msdn&#xff1a;http://msdn.microsoft.com/zh-cn/library/ms478860.aspx轉載于:https://www.cnblogs.com/heavencloud/archive/2009/03/20/141793…

WP7之Application Bar控件

Microsoft.Phone.Shell命名空間中定義了ApplicationBar及其相關類&#xff08;ApplicationBarIconButton和ApplicationBarMenuItem&#xff09;&#xff0c;這些類派生自Object,并完全獨立于常規Silverlight編程中的DependencyObject,UIElement和FrameworkElement類層次結構。A…

TomCat使用以及端口號被占用的處理方法

一.HTTP協議 什么是HTTP協議 HTTP協議&#xff08;HyperText Transfer Protocol&#xff0c;超文本傳輸協議&#xff09;是因特網上應用最為廣泛的一種網絡傳輸協議&#xff0c;所有的WWW文件都必須遵守這個標準。 HTTP請求 HTTP響應 2.如何處理端口被占用 方法一&#xff…

FreeRTOS事件標志組

使用信號量來同步的話&#xff0c;任務只能與單個事務或任務進行同步&#xff0c;有時候某個任務可能會需要與多個事件或任務進行同步&#xff0c;此時信號量就無能為力了&#xff0c;FreeRTOS為此提供了一個可選的解決方法&#xff0c;那就是事件標志組。 0x01 事件標志組 事…

FusionCharts等產品簡介

以前做柱狀圖、餅形圖等圖表都是根據數據繪制出來的靜態圖&#xff0c;偶然看到別人的一套系統&#xff0c;居然可以讓柱狀圖的柱子動畫般的逐個出現&#xff0c;效果還是很不錯的。不要跟我抬杠說不就是展現數據嘛&#xff0c;靜態圖表有什么不好&#xff0c;要知道用戶一般可…

c#foreach循環_C#| 使用foreach循環打印整數數組

c#foreach循環Given an integer array and we have to print its elements using "foreach loop" in C#. 給定一個整數數組&#xff0c;我們必須在C&#xff03;中使用“ foreach循環”打印其元素 。 Syntax for foreach loop: foreach循環的語法&#xff1a; fore…

Eclipse和Tomcat綁定并且將上傳資源到Tomcat上

步驟如下&#xff1a; 創建一個Dynamic Web Project&#xff08;圖一&#xff09; Target runtime 選擇Apache Tomcat v7.0版本&#xff08;圖二&#xff09; 切記要選擇 v7.0 和2.5 &#xff08;若沒有圖二選項見圖三&#xff09; 然后&#xff0c;點擊window --> Prefer…

淺析.NET平臺編程語言的未來走向

在去年的PDC2008召開期間&#xff0c;微軟逐步公開了圍繞.NET和編程語言的很多想法&#xff0c;據此我們可以饒有興趣地對.NET的未來預測一番。 .NET平臺以運行在通用語言運行時(Common Language Runtime&#xff0c;CLR)上的C#和VB.NET作為開端。CLR是通用語言架構(Common Lan…

FreeRTOS任務通知

從v8.2.0版本開始&#xff0c;FreeRTOS新增了任務通知這個功能&#xff0c;可以使用任務通知來代替信號量、消息隊列、事件標志組等這些東西&#xff0c;使用任務通知的話效率會更高。 任務通知在FreeRTOS是一個可選的選項&#xff0c;要使用任務通知的話就需要將宏configUSE_T…

kinect在openni下也能玩摳出人物換背景

之前想了個很拉風的名字《用kinect玩穿越》&#xff0c;但是現在功能還不是很完善&#xff0c;細節處理也不是很好&#xff0c;臉皮沒有足夠的厚&#xff0c;所以呢還是叫換背景吧。 這里面包含兩個技術要點&#xff1a; 一、摳出活動人物 在微軟的SDK里深度圖像的前3位即0-2位…

物聯網基礎知識_聯網| 基礎知識能力問答 套裝1

物聯網基礎知識1) There are the following statements that are given below, which of them are correct about the computer network? A computer network is an interconnection between multiple devices to share hardware resources and information.A computer networ…