微信开发之调起摄像头、本地展示图片、上传下(2)

public void saveImageToDisk(String mediaId, String picName, String picPath) throws Exception { String accessToken = getBaseAccessToken(); InputStream inputStream = getInputStream(accessToken, mediaId); // 循环取出流中的数据 byte[] data = new byte[1024]; int len = 0; FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(picPath+picName+".jpg"); while ((len = inputStream.read(data)) != -1) { fileOutputStream.write(data, 0, len); } LOGGER.info("Write the fileInputStream is successful"); } catch (IOException e) { LOGGER.error("Write the fileInputStream is error"); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { LOGGER.error("Close the fileInputStream is error"); } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e) { LOGGER.error("Close the fileOutputStream is error"); } } } }

 4.总结

那么到这里,简单的拍照,展示图片,上传下载的功能都已经完成,其实代码就是最好的注释!微信开放的jssdk提供了很多友好而有趣的功能,接下来还需要继续实践研究....

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwfxjj.html