Convert InputStream(Image) to ByteArrayInputStream

后端 未结 3 723
抹茶落季
抹茶落季 2020-12-14 02:02

Not sure about how I am supposed to do this. Any help would be appreciated

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 02:39

    Or first convert it to a byte array, then to a bytearrayinputstream.

    File f = new File(arg[0]);
    InputStream in = new FileInputStream(f);
    // convert the inpustream to a byte array
    byte[] buf = null;
    try {
        buf = new byte[in.available()];
        while (in.read(buf) != -1) {
        }
    } catch (Exception e) {
        System.out.println("Got exception while is -> bytearr conversion: " + e);
    }
    // now convert it to a bytearrayinputstream
    ByteArrayInputStream bin = new ByteArrayInputStream(buf);
    

提交回复
热议问题