0

i have a activity where i have a image view..i capture image and image get stored in sd card folder. at the time of capterd image a folder will create in sd card and the respective clicked image stored in sd card card folder. And absolute path of that image inserted in sqlite database. i get the table index of image and split the path to get file/image name..,,i want to know how to check that image name exist in sd card folder or not at the time of post image to server..

String trp=AppDBManager.w1;  ///image name get in Aapdbmanager class variable w1   
       File sdCard = Environment.getExternalStorageDirectory();
        File dir = new File(Environment.getExternalStorageDirectory()+ "/Retailsolution/"+trp+"");

        if(dir.exists()){

            //code 
}
Mushahid Khan
  • 2,816
  • 1
  • 19
  • 32
  • Your code is right, whats the problem? – Nanoc Apr 06 '16 at 08:26
  • i am not getting the image on server.. – vini Bhandari Apr 06 '16 at 08:27
  • when i manually put the name of image in file then got the image on server File dir = new File(Environment.getExternalStorageDirectory() + "/Retailsolution/x-pankaj_Facade_2016-04-05_05-30-29.jpg"); – vini Bhandari Apr 06 '16 at 08:29
  • i want to get image from database without knowing what image name is exactly stored in database .i only get the index and check the file name is exist on sd card or not..if exist then post that to server.. – vini Bhandari Apr 06 '16 at 08:36
  • Possible duplicate of [Check if file exists on SD card on Android](https://stackoverflow.com/questions/7697650/check-if-file-exists-on-sd-card-on-android) – Adriana Hernández Aug 24 '17 at 20:46

3 Answers3

0
File root = new File(Environment.getExternalStorageDirectory(), mFolder);
if (root.exists()) {

    File mFile;
    mFile = new File(root, mFileNameOut);
    if (mFile.exists()) {
        //YOUR CODE
    }
}
Miguel Benitez
  • 2,322
  • 10
  • 22
0

Try this:

File file = new File(path);

if(!file.exists()){
    //your code if file not exists
}else {  

}
Konrad Lindenbach
  • 4,911
  • 1
  • 26
  • 28
ak sacha
  • 2,149
  • 14
  • 19
0
File file = new File(getExternalCacheDir(), "mytextfile.txt" );
if (file.exists()) {
  //Do action
}
Devanshu Dwivedi
  • 693
  • 2
  • 6
  • 18