Java – How to use URLEncoder with UTF-8

How to use URLEncoder with UTF-8… here is a solution to the problem.

How to use URLEncoder with UTF-8

The documentation says I should use UTF-8 with URLEncoder

I tried UTF-8. I get a “Unable to parse symbol” error

URLEncoder.encode(str, "UTF_8");

I

also tried, but the API level is higher than I would like (level 19).

String UTF_8 = java.nio.charset.StandardCharsets.UTF_8.toString();

What is the correct and easy way to use this method for UTF-8?

Solution

The correct way is to spell it correctly. Try URLEncoder.encode(str, "UTF-8"); Do not use underscores.

Related Problems and Solutions