0

I want to read a file from android application . This file is in external storage ( pendrive) connected to android tablet via OTG cable .

I have searched a lot on " how to do this " , but could not get any way . Can you please help me to do that ?

osimer pothe
  • 2,827
  • 14
  • 54
  • 92

1 Answers1

-1

Please Use Below code to read file from Ext Storage:-

String line, certstr = "";

try {
    BufferedReader reader = new BufferedReader(new FileReader("/mnt/sdcard/file.txt"));

        while( ( line = reader.readLine() ) != null)
        {               
            certstr += line;
        }                              
        reader.close();
} catch (FileNotFoundException e2) {
    // TODO Auto-generated catch block
     Toast.makeText(getApplicationContext(), "File not found in /mnt/sdcard/", 2).show();
    e2.printStackTrace();
    return false;
} catch (IOException e2) {
    // TODO Auto-generated catch block
    e2.printStackTrace();
    return false;
}   
  • 1
    The text file will be in pendrive . This pendrive will be connected to Tablet via otg cable . is the same code applicable for this scenario ? – osimer pothe Feb 09 '15 at 06:50