gpt4 book ai didi

flutter - 我是否需要删除存储在 path_provider.getTemporaryDirectory() 中的图像,因为我将其用作临时占位符?

转载 作者:IT王子 更新时间:2023-10-29 06:56:16 33 4
gpt4 key购买 nike

我正在使用一个名为 path_provider 的 flutter 插件。我必须将图像文件存储在 path_provider.getTemporaryDirectory() 中。存储在此处的图像是自动删除还是我必须明确删除。

最佳答案

来自path_provider的文档

Files in this directory may be cleared at any time. This does not returna new temporary directory. Instead, the caller is responsible for creating(and cleaning up) files or directories within this directory. Thisdirectory is scoped to the calling application.

所以你负责清理,也就是说不会自动清理,而是随时可能清理

编辑

您可以按如下方式清除临时目录:

import 'dart:io';
....
Directory dir = await getTemporaryDirectory();
dir.deleteSync(recursive: true);
dir.create(); // This will create the temporary directory again. So temporary files will only be deleted

关于flutter - 我是否需要删除存储在 path_provider.getTemporaryDirectory() 中的图像,因为我将其用作临时占位符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56889814/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com