Trying to check if a file exists in internal storage

前端 未结 3 2028
野的像风
野的像风 2020-12-13 18:14

The following code is how I am trying to identify if a file exists in the internal storage, MODE_PRIVATE.

public boolean isset(String filename){         


        
相关标签:
3条回答
  • 2020-12-13 18:41

    For internal storage, this works for me:

    public boolean isFilePresent(String fileName) {
        String path = getContext().getFilesDir().getAbsolutePath() + "/" + fileName;
        File file = new File(path);
        return file.exists();
    }
    
    0 讨论(0)
  • 2020-12-13 18:48

    Kotlin: This works for me !!

    fun check(path: String?): Boolean
    {
        val file = File(path)
        return file.exists()
    }
    
    0 讨论(0)
  • 2020-12-13 18:53

    hope this method helps you.

    public boolean fileExist(String fname){
        File file = getBaseContext().getFileStreamPath(fname);
        return file.exists();
    }
    
    0 讨论(0)
提交回复
热议问题