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

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

將文件從一個(gè)文件夾復(fù)制到另一個(gè)文件夾

將文件從一個(gè)文件夾復(fù)制到另一個(gè)文件夾

千巷貓影 2022-12-28 10:42:44
我試圖在 Android 路徑出現(xiàn)時(shí)復(fù)制該文件,但沒(méi)有成功,盡管它已經(jīng)作為 AndroidManifest 上的權(quán)限存在,就好像該文件不存在或在那里不知道它一樣。這是一段代碼:public void onActivityResult(int requestCode, int resultCode, Intent data){    switch (requestCode) {        case FILE_SELECT_CODE:            if (resultCode == RESULT_OK) {                Uri uri = data.getData();                String origem = uri.getPath();                File src = new File(origem);                if(src.isFile()){                    Log.d(TAG,src.toString());                }                File root = Environment.getExternalStorageDirectory();                root = new File(root.toString(), "Kcollector/importa/import.csv");                try {                    copy(src,root,true);                } catch (IOException e) {                    e.printStackTrace();                }            }            break;    }    super.onActivityResult(requestCode, resultCode, data);}public static void copy(File origem, File destino, boolean overwrite) throws IOException{    Date date = new Date();    if (destino.exists() && !overwrite){        System.err.println(destino.getName()+" já existe, ignorando...");        return;    }    FileInputStream fisOrigem = new FileInputStream(origem);    FileOutputStream fisDestino = new FileOutputStream(destino);    FileChannel fcOrigem = fisOrigem.getChannel();    FileChannel fcDestino = fisDestino.getChannel();    fcOrigem.transferTo(0, fcOrigem.size(), fcDestino);    fisOrigem.close();    fisDestino.close();    Long time = new Date().getTime() - date.getTime();    System.out.println("Saiu copy"+time);}嘗試復(fù)制時(shí)返回的錯(cuò)誤:W/System.err:java.io.FileNotFoundException:/external_storage/Kcollector/importa/kvendasajustado.csv(沒(méi)有這樣的文件或目錄) W/System.err:在 java.io.FileInputStream.open0(本機(jī)方法)
查看完整描述

1 回答

?
偶然的你

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

檢查運(yùn)行時(shí)權(quán)限或使用第一個(gè)響應(yīng)中指示的方法

public static void copy(File src, File dst) throws IOException {

    InputStream in = new FileInputStream(src);

    try {

        OutputStream out = new FileOutputStream(dst);

        try {

            // Transfer bytes from in to out

            byte[] buf = new byte[1024];

            int len;

            while ((len = in.read(buf)) > 0) {

                out.write(buf, 0, len);

            }

        } finally {

            out.close();

        }

    } finally {

        in.close();

    }

}

最后檢查 url 是否格式正確。否則你可以用斷點(diǎn)調(diào)試(搜索這些詞),并找到問(wèn)題的確切來(lái)源


查看完整回答
反對(duì) 回復(fù) 2022-12-28
  • 1 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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