Source:Combining @Context and @RolesAllowed in a JAX-RS resource?
FileInputStream input = null;
FileOutputStream output = null;
try {
String filePath = new File(getCacheDir(), "tmp").getAbsolutePath();
android.os.ParcelFileDescriptor pfd = getContentResolver ().openFileDescriptor(
sharedFileUri, "r");
if (pfd != null) {
FileDescriptor fd = pfd . getFileDescriptor ();
input = new FileInputStream (fd);
output = new FileOutputStream (filePath);
int read;
byte[] bytes = new byte[4096];
while ((read = input.read(bytes)) != -1) {
output.write(bytes, 0, read);
}
File sharedFile = new File(filePath);
String finalPath = sharedFile.getPath();
}
}catch(Exception ex) {
} finally {
try {
input.close();
output.close();
} catch (Exception ignored) {
}
}