I have a Java program that has the following function: - Receive a string of 800 characters in Hexa format. After that, convert this string in Ascii format. Finally, write this string to a file in a determined directory with the extension ".rec".
However, the program is recording with an unknown number of characters. It is not recording the file with the content that should.
Below are the following: How should be the file being recorded. The format that is currently being recorded. And finally, the Java code where the program do the converting and recording the file.
Looking at the above string as pairs of hex digits, any pair (e.g. "df") that has the high bit set is not ASCII.
Don't know what you expect to happen with"...".
Fernando Skackauskas wrote:
Why do you think than Java can't do that? It can and actually do. But file does not contain characters, it contains bytes. And there are many ways to convert the same character into different set of bytes (those conversions are called "encodings"). That conversion happens in the PrintWriter. As you does not pass an explicit encoding to use, some "default platform encoding" is used to convert characters into bytes. Then your editor reads those bytes and uses a different encoding to convert them back to characters.
Looks like you should not use string manipulations at all. Your file is not text file, it is binary file. So you have to use binary output streams (like FileOutputStream) and just write decoded bytes (not characters).