如何将 .mp4 文件保存到手机的外部存储中?安卓工作室

问题描述

我有一个视频存储在我的 Android 项目的资产文件夹中,我正在尝试将它带到设备的外部存储中。我正在使用这个 Java 代码,问题是我可以看到存储在手机正确目录中的文件,但我无法打开它,因为它似乎已损坏或类似的东西。我想我使用了一些错误功能,但我找不到在哪里。感谢您的帮助。

 File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),"dancingblue.mp4");
                if (!f.exists())
                    try {
                        AssetManager assManager = getApplicationContext().getAssets();
                        InputStream is = null;
                        try {
                            is = assManager.open("dancingblue.mp4");
                        } catch (IOException e) {
                            // Todo Auto-generated catch block
                            e.printstacktrace();
                        }
                        //InputStream caInput = new BufferedInputStream(is);
                        byte[] buffer = new byte[4096];
                        is.read(buffer);
                        FileOutputStream fos = new FileOutputStream(f);
                        int len;
                        while ((len = is.read(buffer)) != -1){
                            fos.write(buffer,len);
                        }
                        fos.flush();
                        is.close();
                        fos.close();
                    } catch (Exception e) { throw new RuntimeException(e); }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)