Hello im trying to do something like this:
private Byte[] getImage() throws IOException {
String imageUrl = ServletContext.class.getClassLoader()
.getResource("static/anImage.jpg")
.getFile();
Byte[] byteObject = new Byte[imageUrl.getBytes().length];
int i = 0;
for (Byte b : imageUrl.getBytes()){
byteObject[i++] = b;
}
return byteObject;
}
But it's wrong. So how to pick up a file from specific directory? Thanks.
ps. I can do something like this:
File file = new File("image.jpg");
byte[] content = Files.readAllBytes(file.toPath());
But still its a path only from the main folder. Dont know how to program for the resources/images folder.
inputstreamfrom resource and covert to bytes