Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to convert ByteBuffer to byte array in Java

1 Answer

0 votes
import java.nio.ByteBuffer;
import java.io.UnsupportedEncodingException;

public class MyClass {
    public static void main(String args[]) throws UnsupportedEncodingException  {
        String s = "Java programming";
        
        ByteBuffer bbuffer = ByteBuffer.wrap(s.getBytes("UTF-8"));

        byte[] array = new byte[bbuffer.remaining()];
        bbuffer.get(array);
        bbuffer.rewind();
        
        for (byte ch : array) {
            System.out.print(ch + " ");
        }
    }
}



/*
run:

74 97 118 97 32 112 114 111 103 114 97 109 109 105 110 103 

*/

 



answered Nov 6, 2021 by avibootz

Related questions

1 answer 122 views
2 answers 143 views
1 answer 94 views
3 answers 190 views
190 views asked Nov 6, 2021 by avibootz
1 answer 112 views
112 views asked Nov 6, 2021 by avibootz
1 answer 85 views
...