![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Aug 2007
Posts: 76
OS: Windows Vista Home Premium
|
java BufferedReader.read() convert to char
Ok, so Java's BufferedReader read method returns an int, but I want to read one char at a time and store them as chars. How can I convert this returned int to a char?
|
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Manager
Join Date: Sep 2004
Location: Colorado
Posts: 981
OS: Mac OS 9.1, Mac OS X 10.5.8, WinXP Pro, FreeBSD 6.0, Gentoo Linux
|
Re: java BufferedReader.read() convert to char
Unless I'm thinking of a different language, you should be able to convert the int directly to a char. At least in C, int and char are both integer types. They just hold different numbers of bytes. Java should allow you to convert an int to a char as long as you use a cast. Something like
// assuming input is a BufferedReader char letter = (char)input.read(); Although it is a narrowing conversion, so you may need to add some code to check cases where the value doesn't fit in a char. Or you could use BufferedReader.readLine() and access each char from the String (using String.charAt() - note this is an instance method).
__________________
![]() Has it been a few days since I replied to your thread? Don't panic! I'm a busy college student and may forget a post if I'm extra busy (or it might just take me a while to be able to do a decent reply). If you still need help and are awaiting my reply after a few days, PM me about it. When posting what errors you get, please give the full message. It makes helping you much easier. Last edited by shuuhen; 05-26-2008 at 07:26 PM. |
|
|
|
![]() |
| Thread Tools | |
|
|