Java中 图片转换为base64编码字符串的方法
1 public static void readToBase64() { 2 String path = "图片路径"; 3 byte[] byt = null; 4 File file = new File(path); 5 try { 6 byt = FileUtils.readFileToByteArray(file); 7 } catch (IOException e) { 8 // TODO Auto-generated catch block 9 e.printStackTrace(); 10 } 11 byte[] encodedBytes = Base64.encodeBase64(byt); 12 String str = new String(encodedBytes); 13 System.out.println(str); 14 }

浙公网安备 33010602011771号