How to save and read directly on the scard

1

Good afternoon

I am new to programming on android, and at the moment I am developing an App that reads me and writes txt files on the sd card, only that I get stuck, since when I try to read the file it always throws the exception of "File Not Found" already try it in several ways and it is always the same message, the file exists in the SD in the path that I indicate, but can not find it, using this instruction:

File SD = Environment.getExternalStorageDirectory();

throws me the route:

"/storage/emulated/0"

already with the name of my file is:

"/storage/emulated/0/datos.txt"

but does not find it, in a query page vi, which indicated that this route indicates the external storage but emulated and not the real path of the real SD mounted in the slot, in the code I performed the validation of the mounted SD and it returns a true, this is the code with which I try to open the file:

if (Environment.getExternalStorageState().equals("mounted")) {
    File SD = Environment.getExternalStorageDirectory();
    if (SD.canRead()) {
        File file = new File(SD.getAbsolutePath(), "datos.txt");
        try {
            FileInputStream fIn = new FileInputStream(file);

and the error is always thrown in the last line, try on a Sony Xperia C4 computer, with Android 5.1 and Huawei Mate 8 with Android 6.0 and the result is the same, I also have the permissions in the manifests, I even put the read and write:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

and the result is always the same, which could be ...? What do I need to do ...?, thank you ...

    
asked by CGuiovani 27.04.2016 в 21:38
source

1 answer

1

Posted in a comment by the OP:

  

I already solved it, instead of using "Environment.getExternalStorageDirectory ();" use System.getenv ("SECONDARY_STORAGE"); and that gives me the route of the SD ... I hope this can serve many ..

    
answered by 13.04.2017 в 15:00