Encode space URL in Java

Description

The following code shows how to encode space URL.

Example


/*from  w w w  .ja v  a  2 s .  co m*/
import java.net.URLEncoder;

public class Main {

  public static void main(String[] args) throws Exception {
    String url = "www.java2s.com ";
    System.out.println(URLEncoder.encode(url, "UTF-8"));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode