android – File.deleteOnExit – 来自评论的Unix技巧

栏目: Android · 发布时间: 5年前

内容简介:这个答案有一个很好的解释:翻译自:https://stackoverflow.com/questions/22606121/file-deleteonexit-unix-trick-from-comments

以下是此方法的源注释:

Note that onAndroid, the application lifecycle does not include VM termination,

so calling this method will not ensure that files are deleted. Instead, you should

use the most appropriate out of:

* Use a {@code finally} clause to manually invoke {@link #delete}.
 * Maintain your own set of files to delete, and process it at an appropriate point
    in your application's lifecycle.
 * Use the Unix trick of deleting the file as soon as all readers and writers have
   opened it. No new readers/writers will be able to access the file, but all existing
   ones will still have access until the last one closes the file.

任何人都可以向我解释它中提到的“Unix技巧”是什么以及如何使用它?

这个答案有一个很好的解释: https://stackoverflow.com/a/5219960/200508 .基本上,这意味着“删除”Unix系统上的文件不会立即从磁盘上删除它;相反,它只是从它所在的目录中删除对该文件的引用.该文件实际上不会被删除,直到所有使用它的进程终止.因此,您可以打开一个临时文件并立即删除它,然后每当程序终止时它将被自动擦除.

翻译自:https://stackoverflow.com/questions/22606121/file-deleteonexit-unix-trick-from-comments


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

深入理解计算机系统(英文版·第2版)

深入理解计算机系统(英文版·第2版)

[美] Randal E. Bryant、[美] David R. O'Hallaron / 机械工业出版社 / 2011-1 / 128.00元

本书是一本将计算机软件和硬件理论结合讲述的经典教程,内容覆盖计算机导论、体系结构和处理器设计等多门课程。本书的最大优点是为程序员描述计算机系统的实现细节,通过描述程序是如何映射到系统上,以及程序是如何执行的,使读者更好地理解程序的行为为什么是这样的,以及造成效率低下的原因。 相对于第1版,本版主要是反映了过去十年间硬件技术和编译器的变化,具体更新如下: 1. 对系统的介绍(特别是实际使......一起来看看 《深入理解计算机系统(英文版·第2版)》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具