Java 从我的应用程序下载时,是否有方法检查文件是否存在
大家好,我在用这个代码Java 从我的应用程序下载时,是否有方法检查文件是否存在,java,android,Java,Android,大家好,我在用这个代码 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new
File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")),
"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
在上网下载之前,是否需要编写一个if语句来检查文件是否已经存在。当我在网页打开前遇到解析错误时
我想可能是这样的,但这是一个失败的笑
File sdCard = Environment.getExternalStorageDirectory();
String fileStr = sdCard.getAbsolutePath() + "/Download";// + "app-release.apk";
File file = new File(fileStr, "Allcast.apk");
if (fileStr == ""){
Intent iAllcasth20 = new Intent(Intent.ACTION_VIEW,
Uri.parse(AllcastH20DL));
startActivity(iAllcasth20);
}else{
Intent promptInstall = new
Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(promptInstall);
}
谢谢
该网站位于名为Allcasth20的页面顶部的一个私有字符串中,对于所有编辑,我深表歉意。不过,我需要为此创建一个方法吗?File File=new File(filePath);-->如果(file.exists()){}……仅此而已。顺便说一下,您的if(fileStr==“”)将无法工作。您必须执行一些操作,例如if(fileStr.equals(“”)或if(fileStr.isEmpty())……永远不要将字符串与==进行比较,感谢刚刚测试brb的家伙们