Quantcast
Channel: Questions in topic: "android sdk"
Viewing all articles
Browse latest Browse all 455

Android InputStream not reading

$
0
0
Hi all, I'm having trouble reading a file I have an Android URI for. I can't convert the URI to a file path so I am reading it via the android API. I can read it just fine if I do it byte by byte like this; AndroidJavaObject inputStream = contentResolver.Call("openInputStream", uri); List data = new List(); while (true) { int b = inputStream.Call("read"); if (b == -1) { break; } data.Add((byte)b); } However this is unusably slow. If I try to read the file in bigger chunks however I get garbage. I've tried writing the data I get back out to disk and, the file is correct using the single byte method, but full of zeros when I use code like this; AndroidJavaObject inputStream = contentResolver.Call("openInputStream", uri); byte[] data = new byte[size]; int bytesRead = 0; while (bytesRead < size) { bytesRead += inputStream.Call("read", data, bytesRead, size - bytesRead); } Can any one suggest what I'm doing wrong? Thanks in advance!

Viewing all articles
Browse latest Browse all 455

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>