We help IT Professionals succeed at work.

converting charcode to String

DaFou
DaFou asked
on
Medium Priority
1,191 Views
Last Modified: 2012-05-05
HI All,

I use lBufferedReader.read() to read single characters from a Stream. But what frustrates me is that it does not return a String but rather an integer.
How do I convert this int to a String?
Comment
Watch Question

Commented:
int i = 10;

String.valueOf(i) will return String "10"

________
radarsh

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
but I need to convert a CharCode to the actual character it represents
String s = "";
while(condition)
    s += (char)br.read();

Author

Commented:
I am trying to read all of an HTTP request. the request are characters but the read() returns a single int per call.
the int returned I suppose is the CharCode.

HOw do I convert the CharCode to the actual character?
Just do it the simple way. Read an int, convert it to char (the conversion here is correct) and add the char to the existing string:

s += (char)br.read();
glad to help
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.