Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

URGENT - converting bytes to Strings  RSS feed

 
Robbie Keenan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
this is very urgent so I'm hopping you can give me a hand!!I'm reading in data from a serial port and I need to change the format from what it is into a String. Anybody know how to do this?? I presume I'll have to use something like InputStreamReader but I don't know how to go about it. I think this particular section of code should go something like this:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
}
//Changing bytes to String code should go here.............
}catch......
 
Matt Siegel
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check out the String class?? Here's the API: http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html
The String class has a constructor that takes a byte array as a parameter:
String(byte[] bytes)
HTH!
Matt
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also convert your input stream to a character stream like this:

When you are ready to use your string, just call

[This message has been edited by Bodie Minster (edited May 02, 2001).]
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!