import java.util.Base64;
public class Base64Example {
public static void main(String[] args) {
// 定义一个字符串
String originalInput = "Hello, World!";
// 使用Base64编码器对字符串进行编码
String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
System.out.println("Encoded String: " + encodedString);
// 使用Base64解码器对编码后的字符串进行解码
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
String decodedString = new String(decodedBytes);
System.out.println("Decoded String: " + decodedString);
}
}
import java.util.Base64;
导入了Java标准库中的Base64工具类。String originalInput = "Hello, World!";
创建了一个简单的字符串。Base64.getEncoder().encodeToString()
方法将字符串转换为Base64编码的字符串。Base64.getDecoder().decode()
方法将Base64编码的字符串还原为原始字符串。上一篇:java数据类型
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站