-1

Maybe this is dupe. If so, sorry. I can't find the answer.

I want to add image on excel spreadsheet for my spring project.
(Spring boot 1.4.2 + JExcelAPI)

Where I have to put the image file?
And how can I target that file?
Not work as below.

new WritableImage(0, 0, 1, 1, 
  new File(getClass().getResource("/src/main/resource/image.png"))
);
Jehong Ahn
  • 1,872
  • 1
  • 19
  • 25
  • 1
    It's better to use the file bytes (as far as I can see WritableImage does not have a constructor with InputStrema). As it was suggested by @EssexBoy the path should be `\image.png`. But access getClass().getResourceAsStream("\image.png") and get the bytes from the stream. Then just use the bytes in constructor. – StanislavL May 08 '17 at 07:54
  • 1
    Possible duplicate of [How do I load a file from resource folder?](http://stackoverflow.com/questions/15749192/how-do-i-load-a-file-from-resource-folder) – JeanValjean May 08 '17 at 08:12

1 Answers1

2

If you use apache commons

You can do this:

new WritableImage(0, 0, 1, 1, IOUtils.toByteArray(getClass().getResourceAsStream("/image.png")));
Essex Boy
  • 7,565
  • 2
  • 21
  • 24