Java URL????????,????????:
-
????????:???URL???,???????????Java????UTF-8???????,???????,????????????????
java.nio.charset.StandardCharsets
??????????? -
??????:URL???????URL??????????,??????????????????????????????,????????????(?"-"?"_"?"."?)?URL?????,???????????,??????????
-
??
java.net.URLEncoder
?:????????URL??????????,??????????????????????????:
import java.net.URLEncoder; import java.nio.charset.StandardCharsets; public class Main { public static void main(String[] args) { String url = "https://example.com/search?q=Java URL编码"; try { String encodedUrl = URLEncoder.encode(url, StandardCharsets.UTF_8.toString()); System.out.println("Encoded URL: " + encodedUrl); } catch (Exception e) { e.printStackTrace(); } } }
??????,????URLEncoder.encode()
???URL????,???????UTF-8????????????,????????,????????????
??,Java URL????????,???????????????????