java.net.URLEncoder.encode(String) 已弃用,我应该改用什么? [英] java.net.URLEncoder.encode(String) is deprecated, what should I use instead?

查看:40
本文介绍了java.net.URLEncoder.encode(String) 已弃用,我应该改用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 java.net.URLEncoder.encode 时收到以下警告:

I get the following warning when using java.net.URLEncoder.encode:

warning: [deprecation] encode(java.lang.String)
         in java.net.URLEncoder has been deprecated

我应该用什么代替?

推荐答案

使用 URLEncoder:

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆