1,直接上代码,复制直接使用
/** * 把数据流写入文件 * @param path * @param bytes */ private void writeFile(String path, byte[] bytes) { try { FileOutputStream out = new FileOutputStream(path);//指定写到哪个路径中 FileChannel fileChannel = out.getChannel(); fileChannel.write(ByteBuffer.wrap(bytes)); //将字节流写入文件中 fileChannel.force(true);//强制刷新 fileChannel.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
2,调用
//保持文件的路径 String path = Environment.getExternalStorageDirectory()+"/fisheye.yuv" ; writeFile(path,Constant.mRgbRes);