繁体   English   中英

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

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

如何得知Android SD卡或内部存储中是否存在任何文件?

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

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

谢谢

您可以使用File.exists()检查File是否存在。

     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();
        }
        }

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

样品1

样品2

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM