Check if file exists on SD card on Android

后端 未结 6 669
悲哀的现实
悲哀的现实 2020-12-05 20:57

I want to check if a text file exists on the SD card. The file name is mytextfile.txt. Below is the code:

FileOutputStream fos = openFileOutput(\"sdcard/myte         


        
6条回答
  •  抹茶落季
    2020-12-05 21:29

    You have to create a file, and set it to be the required file, and check if it exists.

    String FILENAME="mytextfile.txt";
    File fileToCheck = new File(getExternalCacheDirectory(), FILENAME);
    if (fileToCheck.exists()) {
    FileOutputStream fos = openFileOutput("sdcard/mytextfile.txt", MODE_WORLD_WRITEABLE);
    }
    

    Have Fun!

提交回复
热议问题