This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hi, I am working on the Bodgitt and Scarper assignment. I was trying to arite this function: public String read(int recNo) throws RecordNotFoundException; I created a byte array, where the recors values are read into. But when I look at the method definition its return type is array of string. I dont know how to convert byte into string...sorry for asking this basic question.please help me out guys... Thanks
One of the things you had to do for the SCJP was to look at the Java 2 API. So I suggest that you take 30 seconds (it took me 20) to find the solution... But you will probably realize that what you are trying to do is not exactly what you need to do. [ December 14, 2003: Message edited by: Barry Gaunt ]
The return type is a String. You will have to perform the String s = new String(byteArray); for every record field you have and then build a String after all of the fields have been read in. Hope it helps. Zak
Hi Karthik, If you want to take some specific Charset into account (instead of the platform default one), you may use the String constructor which accepts a charset name as second parameter. That's if your input is a byte array. In case your input is a ByteBuffer, have a look at Charset.decode(). Best, Phil.
Originally posted by Karthik Balasubramanian: public String read(int recNo) throws RecordNotFoundException; Originally posted by Vish Kumar: The return type : Is it String or String?
The return type is String This method reads a record and returns an array of fields which make up that record - each field is a String, therefore it is an array of Strings. You might choose to read the entire record as one byte array, and then break that byte array into each individual field and convert it to a String. Alternatively you might choose to read each individual field as a byte array, and convert that to a String. Regards, Andrew