简体   繁体   English

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

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

How can I come to know that any file is exist or not in Android sdcard or internal storage? 如何得知Android SD卡或内部存储中是否存在任何文件?

Case : we don't have exact location directory. 案例:我们没有确切的位置目录。 I want to check that file in any directory. 我想检查任何目录中的文件。

If there is any method or any example to do so please let me know. 如果有任何方法或任何示例,请告诉我。

Thank you 谢谢

You can check whether File exists or not by using File.exists() 您可以使用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();
        }
        }

Please follow below samples available in stackoverflow 请遵循以下stackoverflow中可用的示例

Sample 1 样品1

Sample 2 样品2

I think above links may help 我认为以上链接可能会有所帮助

暂无
暂无

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

相关问题 Android将文件保存到SD卡,而不是内部存储 - Android saving file to SD Card, not internal storage 如何在Android中获取内部存储而不是SD卡? - How can i get internal storage and not sd card in android? 如何从android SD卡和内部存储访问图像和视频 - How to acess images and videos from android SD Card and internal storage Android - 如何从内部存储和 SD 卡中删除 mp3 文件 - Java 代码 - Android - How to delete mp3 file from Internal Storage and SD Card - Java Code Android如何将我的jpeg文件存储在移动内部存储中。 它没有SD卡 - Android how to store my jpeg file in Mobile internal Storage. It doesn't have an SD CARD Android:本地HTML文件加载到WebView的时间是否受存储位置(内部存储/ SD卡/外部SD卡)影响? - Android: is loading time of local HTML file into WebView affected by the storage place (internal storage/sdcard/external sd card)? 当存在SD卡(外部存储)时,如何在Android 4.4的内部存储中创建文件夹 - How to create a folder in internal storage in Android 4.4 when SD card (External storage) is present 如何在android中找到内部(默认手机存储)和外部存储(可移动SD卡)? - How to find Internal(Default Phone Storage ) and External Storage(Removable sd card) in android? Android中的SD卡存储 - SD card storage in android 如何查找内部电话存储,个人数据,内部SD卡,外部SD卡和内存大小的路径? - How to find Path of Internal Phone Storage, Personal Data, Internal SD Card, External SD Card and Memory Size?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM