Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,895 questions

51,826 answers

573 users

How to encoding and decoding URL in Java

2 Answers

0 votes
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Base64.Encoder;

public class MyClass {
    public static void main(String args[]) throws UnsupportedEncodingException {
        String url =  "https://www.collectivesolver.com";

        byte[] bytes_array = url.getBytes("UTF-8");
        
        Encoder encoder = Base64.getUrlEncoder();
        String encode_string = encoder.encodeToString(bytes_array);
        System.out.println(encode_string);

        String decode_string = new String(Base64.getUrlDecoder().decode(encode_string));
        System.out.println(decode_string);
    }
}




/*
run:

aHR0cHM6Ly93d3cuY29sbGVjdGl2ZXNvbHZlci5jb20=
https://www.collectivesolver.com

*/

 



answered Jan 3, 2022 by avibootz
edited Oct 21, 2023 by avibootz
0 votes
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.io.UnsupportedEncodingException;

public class MyClass {
    public static void main(String args[]) throws UnsupportedEncodingException {
        String url =  "https://www.shortinfos.com";

        String encodeUrl = URLEncoder.encode(url, StandardCharsets.UTF_8.toString());
        System.out.println(encodeUrl);
 
        String decodedUrl = URLDecoder.decode(encodeUrl, "UTF-8");
        System.out.println(decodedUrl);
    }
}
 
 
 
 
/*
run:
 
https%3A%2F%2Fwww.shortinfos.com
https://www.shortinfos.com
 
*/

 



answered Oct 21, 2023 by avibootz

Related questions

1 answer 143 views
1 answer 179 views
1 answer 172 views
1 answer 135 views
135 views asked Jan 27, 2024 by avibootz
1 answer 113 views
1 answer 130 views
...