'NotDirectoryException when using Files.copy() to copy from visible storage into getExternalFilesDir(null)
I've been trying to copy files from the visible storage into the app-specific storage and decided on getExternalFilesDir(null) because of the rather large files I'm trying to copy. When testing, both paths seem to be correct, but I'm consistantly getting a java.nio.file.FileSystemException, specifically a NotDirectoryException, which seems odd to me, because as far as I know, Files.copy() doesn't expect directories. Just to give some context: The method is called after choosing a file in a self made file explorer and is given a path to a file somewhere in 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();
}
I'm still new to Android data storage and Android development as a whole, so I'm sorry in advance for any rookie mistakes. I can of course give more context if needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
