为什么将Video Uri转换为Bytearray时出现FileNotFoundException?

时间:2019-07-15 06:59:31

标签: android

我正在将Video Uri转换为字节数组,但出现FileNotFoundException

我已经编写了将Video Uri转换为字节数组的代码

               video = data.getData();
                byte[] buf = new byte[1024];
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                FileInputStream fis;
                try {
                    fis = new FileInputStream(new File(video.getPath()));
                    int n;
                    while (-1 != (n = fis.read(buf)))
                        baos.write(buf, 0, n);
                    fis.close();
                    baos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                 bbytes= baos.toByteArray();

1 个答案:

答案 0 :(得分:0)

尝试使用ContentResolver打开流:

fis = context.getContentResolver().openInputStream(video);