java - UserDefinedFileAttributeView 视图返回 null ,无法设置属性
问题描述
我正在尝试在 android 设备上标记文件,以便稍后根据用户定义的标签(例如 Category 、 Description 、 Owner )显示在列表中。我已经为 UserDefinedFileAttributes 使用了广泛推荐的 java NIO 代码
找到文件路径并报告为有效,但是
final UserDefinedFileAttributeView view = getFileAttributeView (path,
UserDefinedFileAttributeView.class);
总是返回 'view' = null
我错过了什么?
也许并非所有平台/设备都支持 UserDefinedFileAttributeView?我已经在 Nexus 6 (API 28) 的 Android Studio 模拟器上尝试过这段代码
String MEDIA_PATH = Environment.getExternalStorageDirectory().getPath()
+ File.separator + "myEMR" + File.separator +
"Imported_Documents" ;
String uNewFileName = "MyFile";
public void setLocalFileAttributes() throws Exception {
Path path = Paths.get(MEDIA_PATH, uNewFileName);
final UserDefinedFileAttributeView view = getFileAttributeView(path,
UserDefinedFileAttributeView.class);
// The file attribute
final String category = "Category";
final String value = "UnCategorised";
final byte[] bytes = value.getBytes("UTF-8");
final ByteBuffer writeBuffer =
ByteBuffer.allocate(bytes.length);
writeBuffer.put(bytes);
writeBuffer.flip();
view.write(category, writeBuffer);
}
解决方案
推荐阅读
- c# - LINQ 比较 datetime.now ddmmyyyy
- python - 匹配之前没有特定单词的任何点
- python - 为什么我不能在进程中启动线程?
- python - Django REST Framework - 序列化程序看不到字段
- python - 最近成员附加属性分析
- python - 如何使用 if 条件在循环中增加迭代器?
- ssis - catalog.executions 中 process_id 的值从何而来?
- php - 为什么我不能在我的 PHP 网站上上传大文件?
- jquery - 在 Google Developer Network 标签中找不到网络调用的来源
- java - 为什么这个只有静态块的奇怪java代码会编译?