EN
Java example of URLEncoder and URLDecoder (encode, decode, UTF8, UTF-8)
4
points
Example:
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class Example {
public static void main(String[] args) throws UnsupportedEncodingException {
String text = "ą ę";
// spaces are encoded as '+'
String encodedParam = URLEncoder.encode(text, "UTF-8");
System.out.println(encodedParam); // %C4%85+%C4%99
String decode = URLDecoder.decode(encodedParam, "UTF-8");
System.out.println(decode); // ą ę
}
}