Advertisements
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


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):


Advertisements
  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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: