Hi all, I have a byte array and I convert it to string during the execution of my program. After that, I have to convert the string to byte array again but when I compare the original byte array with the one that was converted by the string they are different. I'm using the "UTF8" encode to do all that. Here's a more precise explanation: I have this binary file and when I see its contents in linux I get the following result: ???IL ??I??4:?w? In my program I read this to a byte array and convert it to string as follows: byte block = new byte; FileInputStream rcfg_upt = new FileInputStream(upt); while(true) int bytesRead = rcfg_upt.read(block); // Copies file contents to block if (bytesRead == -1) break; String str = new String(block, "UTF8"); After that I copy the string str to a byte array: byte back = str.getBytes("UTF8"); Problem is when I print the new byte array or when I save it to an output file I get the following value: IL I 4: w a different value from the original. Is there a way to get this right? Thanks.
posted 12 years ago
Hi, It seems like you probably read an int in place of a real char and get these garbage output. Take a look at essentials
"A good method shouldn't bypass one screen long"<br />"genius is the knowledge left when one has forgotten everything"