문제

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