fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // declare sting with "%25+ " inside
  13. String userB = "AAA%25+BBB@DDD.COM";
  14. System.out.println("plain userB: " +userB);
  15. System.out.println("URL-encoded userB: " + java.net.URLEncoder.encode(userB, "UTF8") );
  16. System.out.println("URL-decoded userB: " + java.net.URLDecoder.decode(userB, "UTF8") );
  17.  
  18. // declare sting with "% " inside
  19. String userA = "AAA% BBB@DDD.COM";
  20. System.out.println("plain userA: " + userA);
  21. System.out.println("URL-encoded userA: " + java.net.URLEncoder.encode(userA, "UTF8") );
  22. // DECODING userA raises an runtime-error,
  23. // because percent-sign must be followed by a 2-digit number to be valid decodable
  24. System.out.println("URL-decoded userA: " + java.net.URLDecoder.decode(userA, "UTF8") );
  25.  
  26. }
  27. }
Runtime error #stdin #stdout #stderr 0.04s 2184192KB
stdin
Standard input is empty
stdout
plain userB: AAA%25+BBB@DDD.COM
URL-encoded userB: AAA%2525%2BBBB%40DDD.COM
URL-decoded userB: AAA% BBB@DDD.COM
plain userA: AAA% BBB@DDD.COM
URL-encoded userA: AAA%25+BBB%40DDD.COM
stderr
Exception in thread "main" java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: " B"
	at java.net.URLDecoder.decode(URLDecoder.java:194)
	at Ideone.main(Main.java:23)