简体   繁体   中英

Android check if file exists() not work

I'm checking if the database in a folder of the device exists. The folder and the database exists, but is not found. The path is right, then where am I wrong?

private void checkDBexists() {
    File internal = Environment.getExternalStorageDirectory();
    File myFile = new File(internal.getAbsoluteFile() + "MyFolder/database.db");

    if (myFile.exists()) {
        importaDB();
    } else {
        Toast toast = Toast.makeText(getActivity().getApplicationContext(), "not work", Toast.LENGTH_SHORT);
        toast.show();
    }
}
 File myFile = new File(internal.getAbsoluteFile()+"/MyFolder/database.db");

MyFolder之前添加“ /”。

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