Jalpesh Khakhi
Jalpesh Khakhi

Reputation: 298

How to know the file is exist in SD Card or Internal Storage in Android

How can I come to know that any file is exist or not in Android sdcard or internal storage?

Case : we don't have exact location directory. I want to check that file in any directory.

If there is any method or any example to do so please let me know.

Thank you

Upvotes: 0

Views: 239

Answers (2)

Riskhan
Riskhan

Reputation: 4470

Please follow below samples available in stackoverflow

Sample 1

Sample 2

I think above links may help

Upvotes: 1

onkar
onkar

Reputation: 4547

You can check whether File exists or not by using File.exists()

     File file = new File(filePathString); 
        if(file.exists()) {     
        //File is present
        }
        else{
        // File is not present,Create a new one.
       try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        }

Upvotes: 1

Related Questions