URLEncoder.encode(String s, String enc) has the following syntax.
public static String encode(String s, String enc) throws UnsupportedEncodingException
In the following code shows how to use URLEncoder.encode(String s, String enc) method.
// w w w . j av a2s.c o m import java.net.URLEncoder; public class Main { public static void main(String[] argv) throws Exception { String line = URLEncoder.encode("na me1", "UTF-8") + "=" + URLEncoder.encode("v&al|ue1", "UTF-8"); System.out.println(line); } }
The code above generates the following result.