Android 开发:文件存储、视频播放与录制功能实现
1. Android 文件存储功能实现
在 Android 应用开发中,实现文件的创建、保存和读取是常见需求。下面将详细介绍如何使用 Android Storage Access Framework 来完成这些操作。
1.1 文件保存功能
首先,需要编写代码来保存用户输入的文本到指定文件。以下是关键步骤和代码示例:
1. 获取文件描述符并打开输出流 :
try {
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "w");
FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
String text = editText.getText().toString();
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
pfd.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
- 测试保存功能
超级会员免费看
订阅专栏 解锁全文
335

被折叠的 条评论
为什么被折叠?



