创建于Android的临时文件 [英] Creating temporary files in Android

查看:182
本文介绍了创建于Android的临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是建立在Android的临时文件的最好方法是什么?

What's the best way to create a temporary file in Android?

能否<一href="http://developer.android.com/reference/java/io/File.html#createTempFile%28java.lang.String,%20java.lang.String%29">File.createTempFile使用?该文档是非常模糊了。

Can File.createTempFile be used? The documentation is very vague about it.

在特定的,目前尚不清楚何时与 File.createTempFile 创建的临时文件被删除,如果有的话。

In particular, it's not clear when temporary files created with File.createTempFile are deleted, if ever.

推荐答案

这就是我通常做的:

File outputDir = context.getCacheDir(); // context being the Activity pointer
File outputFile = File.createTempFile("prefix", "extension", outputDir);

至于其删除,我不完全肯定无论是。因为我用这个在我实施的缓存,我手动删除旧的文件,直到缓存目录大小归结到我的preSET值。

As for their deletion, I am not complete sure either. Since I use this in my implementation of a cache, I manually delete the oldest files till the cache directory size comes down to my preset value.

这篇关于创建于Android的临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆