[英]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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.