URL Encoding/Decoding using Base64 in Java Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Base 64 is an encoding scheme that converts binary data into text format so that encoded textual data can be easily transported over network un-corrupted and without any data loss.(Base 64 format reference). The URL encoding is the same as Basic encoding the only difference is that it encodes or decodes the URL and Filename safe Base64 alphabet and does not add any line separation. URL encoding String encodedURL = Base64.getUrlEncoder() .encodeToString(actualURL_String.getBytes()); Explanation: In above code we called Base64.Encoder using getUrlEncoder() and then get the encoded URLstring by passing the byte value of actual URL in encodeToString() method as parameter. URL decoding byte[] decodedURLBytes = Base64.getUrlDecoder().decode(encodedURLString); String actualURL= new String(decodedURLBytes); Explanation: In above code we called Base64.Decoder using getUrlDecoder() and then decoded the URL string passed in decode() method as parameter then convert return value to actual URL. Below programs illustrate the Encoding and Decoding URL in Java: Program 1: URL encoding using Base64 class. Java // Java program to demonstrate // URL encoding using Base64 class import java.util.*; public class GFG { public static void main(String[] args) { // create a sample url String to encode String sampleURL = "https:// www.geeksforgeeks.org/"; // print actual URL String System.out.println("Sample URL:\n" + sampleURL); // Encode into Base64 URL format String encodedURL = Base64.getUrlEncoder() .encodeToString(sampleURL.getBytes()); // print encoded URL System.out.println("encoded URL:\n" + encodedURL); } } Output: Sample URL: https://www.geeksforgeeks.org/ encoded URL: aHR0cHM6Ly93d3cuZ2Vla3Nmb3JnZWVrcy5vcmcv Program 2: URL decoding using Base64 class. Java // Java program to demonstrate // Decoding Basic Base 64 format to String import java.util.*; public class GFG { public static void main(String[] args) { // create a encoded URL to decode String encoded = "aHR0cHM6Ly93d3cuZ2Vla3Nmb3JnZWVrcy5vcmcv"; // print encoded URL System.out.println("encoded URL:\n" + encoded); // decode into String URL from encoded format byte[] actualByte = Base64.getUrlDecoder() .decode(encoded); String actualURLString = new String(actualByte); // print actual String System.out.println("actual String:\n" + actualURLString); } } Output: encoded URL: aHR0cHM6Ly93d3cuZ2Vla3Nmb3JnZWVrcy5vcmcv actual String: https://www.geeksforgeeks.org/ References: https://docs.oracle.com/javase/10/docs/api/java/util/Base64.html https://www.geeksforgeeks.org/dsa/decode-encoded-base-64-string-ascii-string/ https://www.geeksforgeeks.org/dsa/encode-ascii-string-base-64-format/ Comment More infoAdvertise with us Next Article Base conversion in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java 8 Practice Tags : Java Similar Reads Basic Type Base64 Encoding and Decoding in Java Base 64 is an encoding scheme that converts binary data into text format so that encoded textual data can be easily transported over network un-corrupted and without any data loss.(Base 64 format reference).The Basic encoding means no line feeds are added to the output and the output is mapped to a 2 min read Basic Type Base64 Encoding and Decoding in Java Base 64 is an encoding scheme that converts binary data into text format so that encoded textual data can be easily transported over network un-corrupted and without any data loss.(Base 64 format reference).The Basic encoding means no line feeds are added to the output and the output is mapped to a 2 min read Base conversion in Java Given a number in a given base, convert it into another target base.Examples Input : Number = "123" Source Base = 8 Target Base = 10 Output : 83 3 * 1 + 2 * 8 + 1 * 64 = 83 Input : Number = "110" Source Base = 2 Target Base = 10 Output : 6 The idea is to use toString() method present in the Integer 3 min read Base conversion in Java Given a number in a given base, convert it into another target base.Examples Input : Number = "123" Source Base = 8 Target Base = 10 Output : 83 3 * 1 + 2 * 8 + 1 * 64 = 83 Input : Number = "110" Source Base = 2 Target Base = 10 Output : 6 The idea is to use toString() method present in the Integer 3 min read Encrypt and Decrypt String File Using Java In the field of cryptography, encryption is the process of turning plain text or information into ciphertext, or text that can only be deciphered by the intended recipient. A cipher is a term used to describe the encryption algorithm. It secures communication networks and aids in preventing illegal 3 min read Encrypt and Decrypt String File Using Java In the field of cryptography, encryption is the process of turning plain text or information into ciphertext, or text that can only be deciphered by the intended recipient. A cipher is a term used to describe the encryption algorithm. It secures communication networks and aids in preventing illegal 3 min read Like