EN
Java example of URLEncoder and URLDecoder (encode, decode, UTF8, UTF-8)
4 points
Example:
xxxxxxxxxx
1
import java.io.UnsupportedEncodingException;
2
import java.net.URLDecoder;
3
import java.net.URLEncoder;
4
5
public class Example {
6
7
public static void main(String[] args) throws UnsupportedEncodingException {
8
9
String text = "ą ę";
10
11
// spaces are encoded as '+'
12
String encodedParam = URLEncoder.encode(text, "UTF-8");
13
System.out.println(encodedParam); // %C4%85+%C4%99
14
15
String decode = URLDecoder.decode(encodedParam, "UTF-8");
16
System.out.println(decode); // ą ę
17
}
18
}