簡體   English   中英

嘗試從Android Studio中的res-> raw文件夾獲取視頻uri時找不到文件異常

[英]File not found exception while trying to get the video uri from res->raw Folder in Android Studio

我有以下代碼從Android Studio中的res-> raw文件夾中獲取視頻(glass.avi)並保存到SD卡。 但是它顯示文件未找到異常。

 vuri= Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.glass);
        OutputStream out;

        try
        {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            FileInputStream fis = new FileInputStream(new File(String.valueOf(vuri)));

            byte[] buf = new byte[1024];
            int n;
            while (-1 != (n = fis.read(buf)))
                stream.write(buf, 0, n);

            byte[] bytes = stream.toByteArray();




        String root = Environment.getExternalStorageDirectory().getAbsolutePath()+"/";
        File createDir = new File(root+"master"+File.separator);
        createDir.mkdir();


        File file = new File(root + "master" + File.separator +"master.avi");

        file.createNewFile();
        out = new FileOutputStream(file);
        out.write(bytes);
        out.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

它與下面的代碼一起工作。

getResources().getIdentifier("FILENAME_WITHOUT_EXTENSION",
                             "raw", getPackageName());

使其作為InputStream獲得

InputStream ins = getResources().openRawResource(
            getResources().getIdentifier("FILENAME_WITHOUT_EXTENSION",
            "raw", getPackageName()));

暫無
暫無

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

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