final InputStream input = (InputStream) reponse;
String filename = "/ad" + ".mp4";
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + File.separator + "xxx");
myDir.mkdirs();
File file = new File(myDir.getAbsolutePath(), filename);
try {
OutputStream output = new FileOutputStream(file);
try {
try {
byte[] buffer = new byte[4 * 1024]; // or other buffer size
int read;
while ((read = input.read(buffer)) != -1) {
output.write(buffer, 0, read);
}
output.flush();
} finally {
output.close();
}
} catch (Exception e) {
e.printStackTrace(); // handle exception, define IOException and others
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String path=file.getPath().toString();
if (path != null) {
final Message message = new Message();
message.what = VIDEOBUFFER;
message.obj = path;
handler.sendMessage(message);
}
android 保存mp4视频的办法
最新推荐文章于 2022-05-24 11:58:20 发布