URLEncoder

URLEncoder declares the following class method for encoding a string:


String encode(String s, String enc)

import java.net.URLEncoder;

public class Main {

  public static void main(String[] argv) throws Exception {
    String uid = new java.rmi.server.UID().toString(); // guaranteed unique
    String s = URLEncoder.encode(uid,"UTF-8"); // encode any special chars
    System.out.println(s);//455251f6%3A1392632d968%3A-8000
  }
}
Home 
  Java Book 
    Networking