java.net.URL read stream to byte[]

后端 未结 8 477
失恋的感觉
失恋的感觉 2020-11-29 03:11

I`m trying to read an image from an URL (with the java package java.net.URL) to a byte[]. \"Everything\" works fine, except that the content isnt being ent

8条回答
  •  时光说笑
    2020-11-29 04:08

    Use commons-io IOUtils.toByteArray(URL):

    String url = "http://localhost:8080/images/anImage.jpg";
    byte[] fileContent = IOUtils.toByteArray(new URL(url));
    

    Maven dependency:

    
        commons-io
        commons-io
        2.6
    
    

提交回复
热议问题