1.將byte[ ] 中的數據保存成文件
try {
File file1 = new File(Environment.getExternalStorageDirectory()+"/h264");
File file2 = new File(file1,"521.h264");
if(file2.exists()){
file2.delete();
}
file2.createNewFile();
FileOutputStream out = new FileOutputStream(file2);
out.write(byter);
out.flush();
out.clouse();
} catch (IOException e) {
e.printStackTrace();
}
2.讀取文件,轉爲byte[]
String path = Environment.getExternalStorageDirectory()+"/h264/RGBA8888.bm ;
File file = new File(path);
InputStream is = new FileInputStream(file);
byte[] b = toByteArray(is);
private byte[] toByteArray(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024 * 4]; int n = 0; while ((n = in.read(buffer)) != -1) { out.write(buffer, 0, n); } return out.toByteArray(); }