- 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
Java Program to create Stream from a String/Byte Array
Create an input stream and set the string:
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes()));
The getBytes() method is used to convert a string into sequence of bytes and returns an array of bytes.
Now return one single input byte:
(char) inputStream.readByte()
Example
import java.io.ByteArrayInputStream; import java.io.DataInputStream; public class Demo { public static void main(String[] args) throws Exception { DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream("pqrs tu v wxy z".getBytes())); System.out.print((char) inputStream.readByte()); System.out.print((char) inputStream.readByte()); inputStream.close(); } }
Output
Pq
- Related Articles
- Java Program to convert byte[] array to String
- Java Program to convert String to byte array
- Create BigInteger from byte array in Java
- Java Program to read the next byte of data from the input stream
- Java Program to create Character Array from String Objects
- How to convert an input stream to byte array in java?
- Character Stream vs Byte Stream in Java
- Java Program to convert byte to string
- Java Program to convert string to byte
- How to create a string from a Java Array?
- Convert byte Array to Hex String in Java
- Convert Hex String to byte Array in Java
- Java Program to fill elements in a byte array
- C++ program to remove spaces from a string using String stream
- How to convert a byte array to hex string in Java?

Advertisements