Java URLEncoder.encode(String s, String enc)

Syntax

URLEncoder.encode(String s, String enc) has the following syntax.

public static String encode(String s,  String enc)   throws UnsupportedEncodingException

Example

In the following code shows how to use URLEncoder.encode(String s, String enc) method.


//from   www.  j a va 2s  .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.





















Home »
  Java Tutorial »
    java.net »




CookieManager
CookiePolicy
CookieStore
DatagramPacket
DatagramSocket
HttpCookie
HttpURLConnection
InetAddress
JarURLConnection
MulticastSocket
ServerSocket
Socket
SocketAddress
URI
URL
URLConnection
URLDecoder
URLEncoder