简体   繁体   中英

How to extract data from byte array ([B cannot be cast to java.lang.Byte)

I have tried to extract data from byte array my input data as like msg=byte[7064], so I need to extract the data from byte[], below code I tried

byte[] but=new byte [(byte)msg];

When I tried to run it was throwing Classcast exception , I tried my luck but am not able to find any solution , Any help will be appreciate

After converting byte I need to convert as string data, output like name=walterwhite, job=teacher

Below one is correct..

String converted=new String ((byte[])msg,StandardCharsets.ISO_8859_1 );

public static void main(String[] args) {

    byte[] bytes = "hello world".getBytes();
    String s = new String(bytes);

    System.out.println("s = " + s);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM