不推荐使用java.net.URLEncoder.encode(String),我应该使用什么呢? [英] java.net.URLEncoder.encode(String) is deprecated, what should I use instead?
本文介绍了不推荐使用java.net.URLEncoder.encode(String),我应该使用什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 java.net.URLEncoder.encode
时收到以下警告:
warning: [deprecation] encode(java.lang.String)
in java.net.URLEncoder has been deprecated
我应该使用什么?
推荐答案
Use the other encode
method in URLEncoder:
URLEncoder.encode(String, String)
第一个参数是要编码的文本;第二个是要使用的字符编码的名称(例如, UTF-8
)。例如:
The first parameter is the text to encode; the second is the name of the character encoding to use (e.g., UTF-8
). For example:
System.out.println(
URLEncoder.encode(
"urlParameterString",
java.nio.charset.StandardCharsets.UTF_8.toString()
)
);
这篇关于不推荐使用java.net.URLEncoder.encode(String),我应该使用什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文