Home > Java > Java Program to read from byte array using ByteArrayInputStream and print the characters onto console – Q36

Java Program to read from byte array using ByteArrayInputStream and print the characters onto console – Q36

January 18, 2009 Leave a comment Go to comments

Q36: Java Program to read from byte array using ByteArrayInputStream and print the characters onto console.

import java.io.*;
import javax.swing.*;

class B_a_i_s{

	public static void main(String args[]){
		String inp = JOptionPane.showInputDialog("Enter a String:");
		
		byte b_arr[] = inp.getBytes();
		
		ByteArrayInputStream in = new ByteArrayInputStream(b_arr);
		
		int c;
		while((c = in.read()) != -1){
			System.out.print((char)c);

		}
	}
}

… from College notes (BCA/MCA assignments):


Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: