0
我正在使用Windows vista和Eclipse进行开发。我编写简单的 代码来下载文件并将其存储在我的SD卡上。但我得到 异常(文件未找到异常)。 这里是我的代码Android:无法从模拟器写入SD卡
public void downloadNewapk() {
try {
URL url = new URL(apkURL.toString());
HttpsURLConnection c = (HttpsURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory()
+ "/download/";
Log.v("log_tag", "PATH: " + PATH);
File file = new File(PATH);
if (!file.exists()) {
file.mkdirs();
}
File outputFile = new File(file, fileName);
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e) {
Log.d("log_tag", "Error: " + e);
}
Log.v("log_tag", "Check: ");
}
我已经加入用户权限在manifest.xml
和我 Environment.getExternalStorageState()
检查SD卡状态它给人的“删除” 但是,创造了当我加入1GB大小为我的SD卡AVD。 我是新来的android和解决这个对我来说很重要 请任何人都可以帮我
我建议你删除模拟器并重新创建一个。一旦它为我这样工作。 –
我前几天也遇到同样的问题,但我还没有解决它。如果你解决了它,请让我知道。:-) –