java将一个byte数组保存成图片存在本地

java将byte数组转换成图片,可以File和IO操作来完成。

//byte数组到图片到硬盘上
  public void byte2image(byte[] data,String path){
    if(data.length<3||path.equals("")) return;//判断输入的byte是否为空
    try{
    FileImageOutputStream imageOutput = new FileImageOutputStream(new File(path));//打开输入流
    imageOutput.write(data, 0, data.length);//将byte写入硬盘
    imageOutput.close();
    System.out.println("Make Picture success,Please find image in " + path);
    } catch(Exception ex) {
      System.out.println("Exception: " + ex);
      ex.printStackTrace();
    }
  }

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0