簡體   English   中英

Android:無法從模擬器寫入SD卡

[英]Android: Unable to write the SD card from emulator

我正在使用Windows Vista和Eclipse進行開發。 我編寫了簡單的代碼來下載文件並將其存儲在我的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卡的狀態,該狀態為“已刪除”,但是在創建AVD時我為SD卡添加了1GB的大小。 我是android的新手,解決這個問題對我來說真的很重要請任何人都可以幫助我

檢查您是否已創建有權使用寫寫器的emarator的sdcard。

參考: Android Emulator sdcard推送錯誤:只讀文件系統

完成這一步之后,我相信它也會以編程方式為您工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM