java base64转二进制
可以使用Java内置的Base64类,使用decode方法将Base64编码的字符串转换为二进制数组,例如:
import java.util.Base64;
public class Base64Example {
public static void main(String[] args) {
String base64String = "SGVsbG8gV29ybGQ=";
byte[] binaryData = Base64.getDecoder().decode(base64String);
System.out.println("Binary data: " + Arrays.toString(binaryData));
}
}
输出结果为:
Binary data: [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]
其中,Base64.getDecoder()方法返回一个Base64.Decoder对象,可用于解码Base64字符串。调用Decoder的decode方法将Base64字符串转换为二进制数据。
原文地址: https://www.cveoy.top/t/topic/bMYx 著作权归作者所有。请勿转载和采集!