How to read file from usb disk in Android?

I read the Android documentation for USB support at http://developer.android.com/guide/topics/connectivity/usb/host.html and found out that

Android supports USB host mode, we can read any file from a USB device.

In my case, I have a pdf file that is stored in the handle of a USB drive. I want to attach a pen drive to my Android device and want to read pdf data using my phone. Please help me solve this demo project or tutorial link to cover this topic. Thanks

+6
source share
1 answer
String extStorageDirectory = context.getExternalCacheDir().getAbsolutePath(); 

here it gets the path like: /mnt/sdcard/Android/data/com.example/cache

now add ur file name using this path. e.g. abc.txt

/mnt/sdcard/Android/data/com.iris.activity/cache/abc.txt

now use the File class and get an InputStream from this path and read the file from InputStream.

-1
source

All Articles