Java 文件未找到异常-在android SD卡上创建新文件时
在我的应用程序中,我的要求是需要从assets文件夹安装.APK文件,以便我尝试将APK文件从assets文件夹复制到SD卡,我得到的文件未找到异常。 这些代码包含以下代码:Java 文件未找到异常-在android SD卡上创建新文件时,java,android,file,Java,Android,File,在我的应用程序中,我的要求是需要从assets文件夹安装.APK文件,以便我尝试将APK文件从assets文件夹复制到SD卡,我得到的文件未找到异常。 这些代码包含以下代码: String file_path = Environment.getExternalStorageDirectory().getAbsolutePath(); String file_name = "ImageDownloading.apk"; AssetManager assetManager = getAssets(
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath();
String file_name = "ImageDownloading.apk";
AssetManager assetManager = getAssets();
try{
InputStream input = new BufferedInputStream(assetManager.open(file_name));
File path = new File(file_path);
if(!path.exists()){
path.mkdirs()
}
File file = new File(path,file_name);
OutputStream output = new FileOutputStream(file); // Here i get File Not Found Exception error.
byte data[] = new byte[1024];
int count;
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
catch(FileNotFoundException e){
Toast.makeText(MainActivity.this,"File not found exception " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
我花了很多时间,但没有找到解决方案。您的清单文件中是否设置了此权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
谢谢,我忘记了写权限。你知道为什么我们不能从资产文件夹安装apk文件吗?请告诉我技术原因。我想你应该问一个关于Stackoverflow的新问题,这样其他人也可以回答。