简体   繁体   中英

Getting file from sd card to read

just got a little hiccup in getting the file I/O where,a file in the sd is stored under the user given file name. the file name is got through use of intent. Have poked around to see some solution but something seems to be missed out.

The task is, need to get to the path of the given file name where the content of the file is to be read. in the given textview.The file name is got through intent but still the File.io Doesnt seem to get the file to read gives a file not found catch throw exception

have mentioned the required read & write permissions in the manifest files already.

any help with a brief example would be great. Thanks

    public class EmailRead extends Activity {
TextView EtV;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.email_read);

    EtV = (TextView) findViewById(R.id.Email_Txt);

    Intent inn = getIntent();
    String Fname = inn.getStringExtra("FileName");

    File SdC = Environment.getExternalStorageDirectory();

    File file =new File(SdC,SdC.getPath() + "/myDirTab" + "/" + Fname + ".txt");

    if (file.exists()) {
        StringBuilder text = new StringBuilder();

        try {

            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;
            Log.e("This is for inside", "The Bufferreader");
            while ((line = br.readLine()) != null) {
                text.append(line);
                text.append("/n");

            }

        } catch (IOException e) {

            Log.e("Error in reading line ", "In the catch part of read");
        }

            EtV.setText(text);
    } else {

        Log.e("This is for file Exception", "File not found");
    }
}
 }

在崩溃时,在创建文件时或在缓冲的读取器中?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM