我一直在尝试将文件从可见存储复制到特定于应用程序的存储中,并决定使用 getExternalFilesDir(null) 因为我要复制的文件相当大。测试时,两条路径似乎都是正确的,但我一直得到 java.nio.file.FileSystemException,特别是 NotDirectoryException,这对我来说似乎很奇怪,因为据我所知,Files.copy() 没有期望目录。只是给出一些上下文:在自制文件资源管理器中选择一个文件后调用该方法,并在 storage/emulated/0 中的某个位置给出一个文件的路径。
public void clickedAction(Path source) {
Path target = context.getExternalFilesDir(null).toPath().resolve(source.getFileName());
try {
Path file = Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
Activity a = (Activity) context;
a.finish();
}
作为一个整体,我对 Android 数据存储和 Android 开发还是新手,所以对于任何菜鸟的错误,我提前表示歉意。如果需要,我当然可以提供更多背景信息。