Monday 16 June 2014

getBytes (Charset charset)

public byte[] getBytes(Charset charset)
Encodes this String into a sequence of bytes using the given charset, storing the result into a new byte array.

import java.nio.charset.Charset;

class StringGetBytesCharSet{
 public static void main(String args[]){
  String s1 = new String("wxyz");
  Charset c1 = Charset.forName("IBM-Thai");
  byte b[] = s1.getBytes(c1);
  
  System.out.println("s1 = " + s1);
  System.out.println("Bytes are");
  
  for(byte b1 : b)
   System.out.print(b1 + " ");
 }
}

Output
s1 = wxyz
Bytes are
-90 -89 -88 -87


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment