Java String getBytes(Charset charset) Example

Started by VelMurugan, Nov 27, 2008, 12:20 AM

previous topic - next topic
Go Down

VelMurugan

Java String getBytes(Charset charset) Example

String class getBytes(Charset charset) method example

String class getBytes(Charset charset) method example. This example shows you how to use getBytes(Charset charset) method.This method Encodes this String into a sequence of bytes using the given charset, storing the result into a new byte array.

Here is the Code:-

Code: [Select]
/**
* @(#) GetBytes1string.java
*Program that Convert this String into bytes according to the specified character encoding, storing the result into a new byte array.
* @Version  01-May-2008
* @author   Rose India Team
*/
public class GetBytes1string
{
    public static void main(String[] args)
    {
    try
    {
         String str = "Welcome to RoseIndia.";
            // Copy the contents of the String to a byte array using the ASCII encoding.
            byte[] arr = str.getBytes("ASCII");
            // Create a new String using the contents of the byte array.
            String newStr = new String(arr);
            // Display the contents of the byte array.
            System.out.println("The new String equals \"" +newStr + "\"");
      }
    catch (Exception ex)
    {
    }
    }
}

Source : CodeDiary

unselmlaneurn

'Natural disasters' bring out the best in all of us, especially the United States. This weekend, a few Penn State students will join nearly 10,000 others from across the country to rally in the nation’s capital at this year’s Power Shift 2011. FLORENCE (AP) - Cracks have opened in the Florence High School cafeteria and gymnasium and in its athletic stadium.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:
Verification:
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens Web Designing Chennai | GinGly :: SMS Backup | CineBuzz :: Latest Cinema News | My Kids Diary :: Kids magical moment
Copyright 2005 - 2019 :: IT Acumens :: All Rights Reserved.
ITAcumens Forum with 2 lakhs post running for 14 years - Powered by IT Acumens Dedicated Server