import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class URLCodecExample {
    public static void main(String[] args) {
        String data = "Hello World! 你好,世界!";
        try {
            // 使用 UTF-8 编码进行 URL 编码
            String encodedData = URLEncoder.encode(data, "UTF-8");
            System.out.println("原始字符串: " + data);
            System.out.println("URL 编码后的字符串: " + encodedData);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}java.io.UnsupportedEncodingException 和 java.net.URLEncoder。URLCodecExample 的类,并在其中定义 main 方法。data。URLEncoder.encode 方法对字符串进行编码,指定编码格式为 UTF-8。UnsupportedEncodingException 异常。上一篇:java decimal
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站