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
101 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,220 points

Related Questions In Java

0 votes
1 answer

How to convert a java string into byte array

You can probably use ByteBuffer:  byte[] byte = ...READ MORE

answered Jun 21, 2018 in Java by Perry
• 16,450 points
33 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,820 points
1,467 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
33 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,590 points
28 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
38 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,520 points
43 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
2,477 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,310 points
247 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,820 points
51 views
0 votes
1 answer

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

String lString = String.join(", ", list); In case ...READ MORE

answered Apr 26, 2018 in Java by developer_1
• 3,220 points
29 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.