Create a Java File object (or equivalent) using a byte array in memory (without a physical file)

前端 未结 5 675
情深已故
情深已故 2020-12-15 12:38

I want to create a Java File object in memory (without creating a physical file) and populate its content with a byte array.

Can this be done?

T

5条回答
  •  难免孤独
    2020-12-15 13:24

    Maybe its worth trying a different overload of the method:

    addInline(String contentId, 
              InputStreamSource inputStreamSource, 
              String contentType) 
    

    I.e.:

    addInline("cImage", 
              new InputStreamSource () 
              {  
                 final private InputStream src = 
                                         new ByteArrayInputStream(imageByteArr);
                 public InputStream getInputStream() {return src;}
              },
              "image/jpeg"); // or whatever image type you use 
    

提交回复
热议问题