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     }

 

posted @ 2021-02-25 15:53  安宇  阅读(408)  评论(0)    收藏  举报