如何从设备获取视频并转换为字节

时间:2016-09-07 05:41:26

标签: android

我想从设备获取视频,并希望将视频转换为字节,因为我想将数据发送到服务器 这是我的代码

if (requestCode == 4 && resultCode == RESULT_OK && data != null && data.getData() != null) {
        Uri filePath = data.getData();
        File file = new File(filePath.getPath());
        String s = file.getName();
        try {
            byte[] bytes1 = loadFile(file.getAbsoluteFile());
            Toast.makeText(CreateEmailCampaign.this, bytes1.toString(), Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            e.printStackTrace();

        }
    }

这里是loadfile方法

private static byte[] loadFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);

        long length = file.length();
        if (length > Integer.MAX_VALUE) {
            // File is too large
        }
        byte[] bytes = new byte[(int) length];

        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
                && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
            offset += numRead;
        }

        if (offset < bytes.length) {
            throw new IOException("Could not completely read file " + file.getName());
        }

        is.close();
        return bytes;
    }

它始终显示

java.io.filenotfoundexception在android中打开失败的enoent(没有这样的文件或目录)

0 个答案:

没有答案