android - 在android mediastore中保存文件时如何覆盖文件?
问题描述
我正在使用以下源将文件保存在 Android Q 或更高版本中。
但是如果有文件
另存为文件名(1)、文件名(2)、文件名(3)...
我想知道如何覆盖文件
try {
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DISPLAY_NAME, "menuCategory"); //file name
values.put(MediaStore.MediaColumns.MIME_TYPE, "text/plain"); //file extension, will automatically add to file
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS + "/Kamen Rider Decade/"); //end "/" is not mandatory
Uri uri = getContentResolver().insert(MediaStore.Files.getContentUri("external"), values); //important!
OutputStream outputStream = getContentResolver().openOutputStream(uri);
outputStream.write("This is menu category data.".getBytes());
outputStream.close();
Toast.makeText(view.getContext(), "File created successfully", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(view.getContext(), "Fail to create file", Toast.LENGTH_SHORT).show();
}
解决方案
推荐阅读
- amazon-web-services - 使用 AWS Toolkit for Cloud9 在本地导入、编辑和调试 Lambda 函数
- java - Spring Boot 5 中的持久化 API 令牌
- typescript - Nest.js Graphql Nested InputType 抛出引用错误
- azure - 如何使用其他 Azure 服务对 IoT Central 设备进行身份验证?(例如:下载OTA bin)
- c# - 文档 | 为什么 API 返回“资源不支持 http 方法 'POST'” | C#
- python-3.x - 在 Python 中从 SQL 数据库打印正确的列表项
- javascript - VBA Web 自动化:触发文本输入的 Return/Tab 事件
- db2 - DB2 使用 CASE 替换字符串时
- spring - 将 REST API 添加到 Spring MVC 应用程序
- java - 如何使用倒车法添加多个解决方案