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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈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…