第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在SD卡上自動(dòng)創(chuàng)建目錄

如何在SD卡上自動(dòng)創(chuàng)建目錄

白衣非少年 2019-08-15 15:09:28
如何在SD卡上自動(dòng)創(chuàng)建目錄我正在嘗試將我的文件保存到以下位置,F(xiàn)ileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); 但是我得到了異常java.io.FileNotFoundException但是,當(dāng)我把路徑保存"/sdcard/"起來(lái)的時(shí)候?,F(xiàn)在我假設(shè)我無(wú)法以這種方式自動(dòng)創(chuàng)建目錄。有人可以建議如何創(chuàng)建directory and sub-directory使用代碼嗎?
查看完整描述

3 回答

?
www說(shuō)

TA貢獻(xiàn)1775條經(jīng)驗(yàn) 獲得超8個(gè)贊

如果您創(chuàng)建一個(gè)包裝頂級(jí)目錄的File對(duì)象,您可以調(diào)用它的mkdirs()方法來(lái)構(gòu)建所有需要的目錄。就像是:

// create a File object for the parent directory

File wallpaperDirectory = new File("/sdcard/Wallpaper/");

// have the object build the directory structure, if needed.

wallpaperDirectory.mkdirs();

// create a File object for the output file

File outputFile = new File(wallpaperDirectory, filename);

// now attach the OutputStream to the file object, instead of a String representation

FileOutputStream fos = new FileOutputStream(outputFile);

注意:使用Environment.getExternalStorageDirectory()來(lái)獲取“SD卡”目錄可能是明智之舉,因?yàn)槿绻謾C(jī)出現(xiàn)了除SD卡以外的其他東西(例如內(nèi)置閃存,則可能會(huì)更改)蘋果手機(jī))。無(wú)論哪種方式,您都應(yīng)該記住,您需要檢查以確保它實(shí)際存在,因?yàn)榭赡軙?huì)移除SD卡。


更新:自API級(jí)別4(1.6)起,您還必須請(qǐng)求許可。這樣的事情(在清單中)應(yīng)該有效:


<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


查看完整回答
反對(duì) 回復(fù) 2019-08-15
?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

這對(duì)我有用。

 uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

在你的清單和下面的代碼中

public static boolean createDirIfNotExists(String path) {
    boolean ret = true;

    File file = new File(Environment.getExternalStorageDirectory(), path);
    if (!file.exists()) {
        if (!file.mkdirs()) {
            Log.e("TravellerLog :: ", "Problem creating Image folder");
            ret = false;
        }
    }
    return ret;}


查看完整回答
反對(duì) 回復(fù) 2019-08-15
  • 3 回答
  • 0 關(guān)注
  • 560 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)