- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
convert InputStream to ByteArray in java
Following method can be used to convert an InputStream to a Byte[].
Example
public static byte[] getBytes(InputStream is) throws IOException { try (ByteArrayOutputStream os = new ByteArrayOutputStream();) { byte[] buffer = new byte[1024]; for (int len = 0; (len = is.read(buffer)) != -1;) { os.write(buffer, 0, len); } os.flush(); return os.toByteArray(); } }
- Related Articles
- Java Program to Convert InputStream to String
- How to convert InputStream to byte array in Java?
- How to convert InputStream object to a String in Java?
- Java Program to Convert a String into the InputStream
- How to convert a String to an InputStream object in Java?
- String to byteArray in Arduino
- When to use the readAllBytes() method of InputStream in Java 9?
- When to use the readNBytes() method of InputStream in Java 9?
- Importance of transferTo() method of InputStream in Java 9?
- Convert Java String to Short in Java
- Convert IntStream to String in Java
- Convert String to IntStream in Java
- Convert List to Set in Java
- Convert Stream to Set in Java
- Convert Double to Integer in Java

Advertisements