String filePath ="D:\\Alivin\\Temp\\img\\c.jpg"; byte[] b = Files.readAllBytes(Paths.get(filePath)); String s = Base64.getEncoder().encodeToString(b);