Created
April 12, 2019 07:46
-
-
Save r0xsh/e617021b63033a2a4939a9e15879af1d to your computer and use it in GitHub Desktop.
Android: Read file contents from Uri
This file contains hidden or 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