Convert String into a BYTE array, convert to String

xiaoxiao2021-03-05  23

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 = "Instructions";

// arraylist slist (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 automatic generation れ れ at ブ ブ ッ ク E1.PrintStackTrace ();}

转载请注明原文地址:https://www.9cbs.com/read-36398.html

New Post(0)