Encoding as Base64 in Java

前端 未结 17 2482
失恋的感觉
失恋的感觉 2020-11-21 13:44

I need to encode some data in the Base64 encoding in Java. How do I do that? What is the name of the class that provides a Base64 encoder?


I tried to use the <

17条回答
  •  日久生厌
    2020-11-21 14:00

    In Java 7 I coded this method

    import javax.xml.bind.DatatypeConverter;
    
    public static String toBase64(String data) {
        return DatatypeConverter.printBase64Binary(data.getBytes());
    }
    

提交回复
热议问题