-
-
Save bsodhi/75021aaef862a2d9469e32423ec44998 to your computer and use it in GitHub Desktop.
Android: Read file contents from Uri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] readUri(Context context, Uri uri) throws IOException { | |
ParcelFileDescriptor pdf = context.getContentResolver().openFileDescriptor(uri, "r"); | |
assert pdf != null; | |
assert pdf.getStatSize() <= Integer.MAX_VALUE; | |
byte[] data = new byte[(int) pdf.getStatSize()]; | |
FileDescriptor fd = pdf.getFileDescriptor(); | |
FileInputStream fileStream = new FileInputStream(fd); | |
fileStream.read(data); | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment