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

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

創(chuàng)建Android外部存儲(chǔ)器文件問題

創(chuàng)建Android外部存儲(chǔ)器文件問題

暮色呼如 2019-03-13 14:15:53
我想創(chuàng)建一個(gè).txt文件并將其存儲(chǔ)在Android手機(jī)的外部存儲(chǔ)器。我增加了Android Manifest權(quán)限。我運(yùn)行代碼時(shí)不給出任何錯(cuò)誤提示,但文件卻創(chuàng)建不了。我不知道代碼哪里出錯(cuò),請(qǐng)高人指點(diǎn),謝謝。public void createExternalStoragePrivateFile(String data) {     // Create a path where we will place our private file on external     // storage.     File file = new File(myContext.getExternalFilesDir(null), "state.txt");     try {         FileOutputStream os = null;          OutputStreamWriter out = null;         os = myContext.openFileOutput(data, Context.MODE_PRIVATE);         out = new OutputStreamWriter(os);         out.write(data);         os.close();         if(hasExternalStoragePrivateFile()) {             Log.w("ExternalStorageFileCreation", "File Created");         } else {             Log.w("ExternalStorageFileCreation", "File Not Created");         }     } catch (IOException e) {         // Unable to create file, likely because external storage is         // not currently mounted.         Log.w("ExternalStorage", "Error writing " + file, e);     } }
查看完整描述

3 回答

?
慕勒3428872

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

File file = new File(myContext.getExternalFilesDir(null), "state.txt");

try {


     FileOutputStream os = new FileOutputStream(file, true); 

     OutputStreamWriter out = new OutputStreamWriter(os);

         out.write(data);

     out.close();

}


查看完整回答
反對(duì) 回復(fù) 2019-04-26
?
森林海

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

你需要添加一個(gè)正確的權(quán)限:

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


查看完整回答
反對(duì) 回復(fù) 2019-04-26
?
莫回?zé)o

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

我之前也遇見過這個(gè)問題,用這段代碼能實(shí)現(xiàn):

 public void createExternalStoragePrivateFile(String data) {
        // Create a path where we will place our private file on external
        // storage.
        File file = new File(myContext.getExternalFilesDir(null), "state.txt");


        try {

            FileOutputStream os = new FileOutputStream(file); 
            OutputStreamWriter out = new OutputStreamWriter(os);

            out.write(data);
            out.close();

            if(hasExternalStoragePrivateFile()) {
                Log.w("ExternalStorageFileCreation", "File Created");
            } else {
                Log.w("ExternalStorageFileCreation", "File Not Created");
            }

        } catch (IOException e) {
            // Unable to create file, likely because external storage is
            // not currently mounted.
            Log.w("ExternalStorage", "Error writing " + file, e);
        }
    }


查看完整回答
反對(duì) 回復(fù) 2019-04-26
  • 3 回答
  • 0 關(guān)注
  • 774 瀏覽
慕課專欄
更多

添加回答

舉報(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)