The java.net.URLEncoder.code(String) was deprecated. What should I write instead of this?

Asked 2 years ago, Updated 2 years ago, 93 views

java.net.URLEncoder.encode I was going to use this

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

I got this warning. So what should I write instead of that?

url java network-programming deprecated

2022-09-22 22:17

1 Answers

You can use a method called code in the URL Encoder class. URLEncoder.encode(String, String) The first parameter is the text to encode, and the second parameter is the encoding type such as UTF-TF-8.

System.out.println(
  URLEncoder.encode(
    "urlParameterString",
    java.nio.charset.StandardCharsets.UTF_8.toString()
  )
);


2022-09-22 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.