How do I convert an input stream into a byte array

0 votes
I want to read an input stream into a byte array. what is the best way to do that.
Apr 25, 2018 in Java by Akrati
• 3,150 points
267 views

1 answer to this question.

0 votes

There is a simple solution without the need for importing any 3rd party library.

InputStream inStream;
byte[] array = inStream.readAllBytes();

This method was introduced in Java 9 .

answered Apr 25, 2018 by developer_1
• 3,280 points

Related Questions In Java

0 votes
2 answers

How to convert a java string into byte array

Try using String.getBytes(). It returns a byte[] ...READ MORE

answered 43 minutes ago in Java by Sirajul
• 18,690 points
46 views
0 votes
2 answers

How do I read and convert an InputStream object to string type?

You can also use Java Standard Library ...READ MORE

answered Jul 17, 2018 in Java by Sushmita
• 6,850 points
2,796 views
+1 vote
3 answers

How to convert a List to an Array in Java?

Either: Foo[] array = list.toArray(new Foo[list.size()]); or: Foo[] array = ...READ MORE

answered Aug 7, 2018 in Java by Akrati
• 3,150 points
50 views
0 votes
1 answer

How to convert a byte into Hexadecimal in Java?

byte[] bytes = {-1, 0, 1, 2, ...READ MORE

answered Aug 21, 2018 in Java by parth295
• 4,600 points
32 views
0 votes
3 answers

How to convert File to Byte[] in Java?

import java.io.File; import java.nio.file.Files; File file; // ...(file is initialised)... byte[] ...READ MORE

answered Aug 14, 2018 in Java by samarth295
• 2,190 points
61 views
0 votes
1 answer

Convert String type to byte[] in Java

Try using String.getBytes(). It returns a byte[] ...READ MORE

answered May 8, 2018 in Java by Rishabh
• 3,540 points
57 views
+2 votes
10 answers

Convert Java Byte Array - String - Byte Array

Character Stream Vs Byte Stream Character oriented are ...READ MORE

answered Sep 25, 2018 in Java by carldivin
• 180 points
3,035 views
0 votes
1 answer

How can I convert byte array into hex string in Java?

private final static char[] hexarr = "0123456789ABCDEF".toCharArray(); public ...READ MORE

answered May 24, 2018 in Java by sharth
• 3,320 points
323 views
0 votes
3 answers

How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

answered Sep 19, 2018 in Java by Sushmita
• 6,850 points
94 views
0 votes
2 answers

what is the best way to convert an ArrayList to a String

You could probably use the Joiner class ...READ MORE

answered 3 days ago in Java by Sirajul
• 18,690 points
47 views