When i make File file = new File(etc..) i actuly created that file on SD card? Iam bit confused because everytime my condition is true and program jumps in if tree but in that time there is no file on SD card...

    String filename = "pictures.data";
    String root = Environment.getExternalStorageDirectory().toString();
    File dir = new File(root + "/courier/saved/");
    File file = new File(dir,filename);

    if (file.exists())
        // program jumps here
    else{

    }
有帮助吗?

解决方案

OK so you can see the file in a dir /courier/saved/. Anyway here's my answer

String filename = "pictures.data";
String root = Environment.getExternalStorageDirectory().toString();
File dir = new File(root + "/courier/saved/");
File file = new File(dir,filename);
file.mkdirs();
if (file.exists())
    // program now stops here
else{

}

Best would be to create the dir beforehand maybe, But this creates it on the fly

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top