When you try to use .copyTo() on a file which is obtained by using .listFiles() from a DocumentFileCompat created through .fromTreeUri() you get an error: "java.lang.UnsupportedOperationException: Cannot open a stream on a tree" even when the file is not a tree (folder). This requires using the .copyFrom() or custom file copy method instead.
When you try to use .copyTo() on a file which is obtained by using .listFiles() from a DocumentFileCompat created through .fromTreeUri() you get an error: "java.lang.UnsupportedOperationException: Cannot open a stream on a tree" even when the file is not a tree (folder). This requires using the .copyFrom() or custom file copy method instead.