UTF-8 encoding vs Base-64 Encoding
<p>I want to encode a file it may be image or any pdf and send it to server. Which type of Encoding and decoding I have to follow. (Both server and client is in our company. we can write logic in both place). <strong>UTF-8 Encoding</strong> is by default supported in java. and to use <strong>Base-64</strong> encoding I have to import external jar. for simple texts both the ways are working fine. I am using tcp socket programming.</p>

<p><strong>Using UTF-8 Encoding</strong></p>

<pre><code>String str = "This is my Sample application";
        String urlEncodedData = URLEncoder.encode(str, "UTF-8"); // Encoding with UTF-8
        System.out.println("..after URL Encodingencoding..."+urlEncodedData );
        String retrievedData = URLDecoder.decode(urlEncodedData , "UTF-8");// Decoding with UTF-8
        System.out.println("..after decoding..."+retrievedData ); 
</code></pre>

<p><strong>Using Base-64 (Using commons.codec jar of apache</strong></p>

<pre><code>byte[] b =Base64.encodeBase64(str.getBytes()); //Encoding  base 64
        Base64.decodeBase64(b); // Decoding with Base 64
</code></pre>
