Android 如何知道文件存在于 SD 卡或内部存储中

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

我怎样才能知道 Android SD 卡或内部存储中是否存在任何文件?

案例:我们没有确切的位置目录。我想检查任何目录中的那个文件。

如果有任何方法或任何例子可以做到这一点,请告诉我。

谢谢

您可以使用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();
        }
        }

请遵循以下 Whosebug 中可用的示例

Sample 1

Sample 2

我认为以上链接可能有帮助