Java - convert buffer to string (economical way) -
I read something to buffer:
char buf [] = new cell [4096]; Int found = Reader. Reid (Buffet, 0, 4096); readLine () is not okay because the stuff can contain "\ n" characters.
Then I want to convert the Buff [] to string. String.valueOf (buf) size will be buf.length () == 4096 and will eventually include junk. I need a string of shapes found There are 2 distorted ways to do this first way - create new array of sizes found , copy the byte to a new array and string Valveoff Another way - to add four axes to the string, add the string by adding letters. Is it a better way to avoid odd actions?
/ Blockquote> You can use the String Constructor
(buf, 0, found);
Sample code:
four buffs [] = new four [4096]; Buf [0] = 'one'; Buf [1] = 'b'; Buf [2] = 'c'; Int found = 2; String s = new string (buff, 0, found); Println (s); // ab
Comments
Post a Comment