Conversion of Byte to String

package ch4_package;
import java.io.*;
public class Test_This {
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str_b="java string", str ="", str_bool, str_toSTR;
try{
System.out.println("---While Loop---");
System.out.print("Please type word java string: ");
str = br.readLine();
boolean b;
byte b1;
//b = (str.endsWith(str_b))? true : false;
b = (str.equals(str_b))? true : false;
if (b){
System.out.println("You are got a java: ");
str_bool = b ? "true":"false";
//b1 = (byte)str;
int x = str.length();
b1 = (byte)x;
str_toSTR = Integer.toString(b1);
System.out.println("Integer.toString(b1) is \t "+str_toSTR + " character long");
System.out.println("boolean "+ b + "\tstring boolean\t" + str_bool );
}
else
{
System.out.print("sorry you cant' have a character: ");
}
System.out.println();
}//try
catch(NumberFormatException e) { System.out.println("data was blank");}
}
}

 

Below is a simple example how to get byte from a string data type

import java.io.*;
public class Test_This {
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str ="", str2="";
try{
System.out.println("---While Loop---");
System.out.print("Please type some word: ");
str = br.readLine();
int n1 = str.length();
byte b = (byte)n1;
str2 =Integer.toString(b);
System.out.println("length of the string and byte "+ str2 +"\t"+b);

}//try
catch(NumberFormatException e) { System.out.println("data was blank");}

}

}