android - file.exists() returns false for existing file (for anything different than pdf)

前端 未结 4 813
感动是毒
感动是毒 2020-12-31 05:19

Both files are present on the sdcard, but for whatever reason exists() returns false the the png file.

//String path = \"/mnt/sdcard/Android/data/com.gemoro.         


        
4条回答
  •  滥情空心
    2020-12-31 05:51

    Check file exist in internal storage

    Example : /storage/emulated/0/FOLDER_NAME/FILE_NAME.EXTENTION

    1. check permission (write storage)

    2. and check file exist or not

      public static boolean isFilePresent(String fileName) { return getFilePath(fileName).isFile(); }

    3. get File from the file name

      public static File getFilePath(String fileName){ String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); File folder = new File(extStorageDirectory, "FOLDER_NAME"); File filePath = new File(folder + "/" + fileName); return filePath; }

提交回复
热议问题