【问题标题】:How to know the file is exist in SD Card or Internal Storage in Android如何知道文件存在于 SD 卡或 Android 的内部存储中
【发布时间】:2016-06-09 05:52:28
【问题描述】:

我如何知道任何文件在 Android sdcard 或内部存储中是否存在?

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

如果有任何方法或示例,请告诉我。

谢谢

【问题讨论】:

    标签: android file android-sdcard


    【解决方案1】:

    请按照 stackoverflow 中的以下示例进行操作

    Sample 1

    Sample 2

    我认为上面的链接可能会有所帮助

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 感谢您的回复,但我不知道文件路径是什么。我只有它的名字。然后请告诉我如何从整个 sdcard 中检查它?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      相关资源
      最近更新 更多