Converts a string to a byte array.

Source: Internet
Author: User

Package JP. co. Hitachi. gemplanet2.base. Controller;

Import java. Io. bufferedreader;
Import java. Io. file;
Import java. Io. filereader;
Import java. Io. unsupportedencodingexception;
Import java. util. arraylist;
Import java. util. stringtokenizer;
Import java. NiO. charset. charset;
Import java. NiO .*;

Public class test {

Public static void main (string [] ARGs ){

String temp = "";


// Arraylist slist = tofilelayoutlist (tempstr );

// System. Out. println (slist );



Charset cs = charset. forname ("UTF-8 ");
Bytebuffer BB = cs. encode (temp );

String S1 = "";
String S2 = "";
Bytebuffer BB2;
Bytebuffer bb3;
Try {
Byte [] result = new byte [temp. getbytes ("UTF-8"). Length];
BB2 = BB. Get (result, 0, 4 );
S1 = new string (result, "UTF-8 ");
BB2 = bb2.get (result, 0, 4 );
S2 = new string (result, "UTF-8 ");
System. Out. println (temp. getbytes ("UTF-8"). Length );
} Catch (exception e ){

}
System. Out. println (S1 );
System. Out. println (S2 );

//

Try {
Byte [] result2 = s1.getbytes ("UTF-8 ");
Byte [] result3 = s2.getbytes ("UTF-8 ");
Bb3 = bytebuffer. Allocate (result2.length + result3.length );
Bb3.put (result2 );
Bb3.put (result3 );
// Byte [] result4 = new byte [BB. Array (). Length];
Byte [] result = bb3.array ();
String STR = new string (result, "UTF-8 ");
System. Out. println (STR );

} Catch (exception E1 ){
// Todo automatically generates automatically generated writable catch writable
E1.printstacktrace ();
}

}
// Private Static arraylist tofilelayoutlist (string str_data_file_layout ){
// String rsv_item_text = "";
// Arraylist rsv_item_textlist = new arraylist (20 );
// String strtemp = str_data_file_layout;
// For (INT I = 0; I <20; I ++ ){
//
// If (strtemp. Length ()> = 5 ){
// Rsv_item_textlist.add (strtemp. substring (0, 4 ));
//
// Strtemp = strtemp. substring (4, strtemp. Length ());
//
//} Else {
// If (strtemp. Length ()> 0 ){
// Rsv_item_textlist.add (strtemp. substring (0, strtemp. Length ()));
// Strtemp = "";
//} Else {
// Rsv_item_textlist.add ("");
//}
//}
//}
// Return rsv_item_textlist;
//}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.