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 ?

4

1 回答 1

-1

请使用以下代码从 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;
}   
于 2015-02-09T06:03:39.747 回答