我有以下代码从Android studio中的res-> raw文件夹中获取视频(glass.avi)并保存到sd卡。但它显示文件未找到异常。在Android Studio中尝试从res-> raw文件夹中获取视频uri时发现文件异常
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();
}
2017-10-09
djac
+0
它必须 –
+0
AVI,也支持格式支持的格式(3GP,WMV,MP4)。 –
+0
[支持的视频格式的官方列表](https://developer.android.com/guide/topics/media/media-formats.html#core) –