import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
public class URLDecodeExample {
public static void main(String[] args) {
try {
// 需要解码的URL字符串
String encodedURL = "https://example.com/path%20with%20spaces?query=java%20url%20decode";
// 使用URLDecoder.decode进行解码,指定字符集为UTF-8
String decodedURL = URLDecoder.decode(encodedURL, StandardCharsets.UTF_8.toString());
// 输出解码后的URL
System.out.println("Decoded URL: " + decodedURL);
} catch (Exception e) {
e.printStackTrace();
}
}
}
%20
)转换回原始字符。这段代码展示了如何使用URLDecoder.decode
方法对一个URL编码的字符串进行解码,并输出解码后的结果。
下一篇:java json字符串转对象
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站