I need to read a image in java ad convert to byte array for postgreSQL. I have tried the following code, is it ok?
import java.nio.file.Files;
import java.nio.file.Path;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Arrays;
public class ConvertImage {
public static void main(String[] args) throws IOException {
Path filepath = Paths.get("image.jpg");
byte[] byteContent = Files.readAllBytes(filepath);
System.out.println(Arrays.toString(byteContent));
}
}
And how to do the way back, form byte array to image?