Click here to watch in Youtube :
https://www.youtube.com/watch?v=I6-B8s5CqqQ&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java String [getBytes(String charsetName) method] |
import java.io.UnsupportedEncodingException; /* * public byte[] getBytes(String charsetName) throws * UnsupportedEncodingException * * Parameters: * ---------- * charsetName - The name of a supported charset. * * Returns: * ------- * The resultant byte array * * Throws: * ------ * UnsupportedEncodingException - If the named * charset is not supported */ public class GetBytesDemo { public static void main(String[] args) { String str = "Hi"; try { byte[] byteArray = str.getBytes("UTF-8"); System.out .println("byteArray of \"Hi\" with charsetName \"UTF-8\" = " + byteArray); for (byte b : byteArray) { System.out.println(b); } System.out.println("--------------------"); byteArray = str.getBytes("ISO-8859-1"); System.out .println("byteArray of \"Hi\" with charsetName \"ISO-8859-1\" = " + byteArray); for (byte b : byteArray) { System.out.println(b); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
byteArray of "Hi" with charsetName "UTF-8" = [B@1a93a7ca 72 105 -------------------- byteArray of "Hi" with charsetName "ISO-8859-1" = [B@66cd51c3 72 105
Refer:
https://en.wikipedia.org/wiki/List_of_Unicode_characters
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringDemo_getBytes_charsetName_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_getBytes_charsetName_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/219b10088440d75a7105e6bff5bbab9e88ad9a80/BasicJava/StringDemo_getBytes_charsetName_App/?at=master
See also:
No comments:
Post a Comment