ISO-8859-1
Encoding Example
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
public class ExtendedAscii {
public static void main(String [] args) {
// Include the Euro sign, which is in Extended ASCII
String text = "Hello, World! €";
byte[] encodedBytes = text.getBytes(StandardCharsets.ISO_8859_1);
String encodedString = new String(encodedBytes, StandardCharsets.ISO_8859_1);
System.out.println("Input Text Bytes: " + Arrays.toString(encodedBytes));
System.out.println("Encoded String: " + encodedString);
}
}
Decoding Example
import java.nio.charset.StandardCharsets;
public class ExtendedAscii {
public static void main(String [] args) {
byte[] encodedBytes1 = {72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 32, (byte) 0x80}; // Hello, World! €
String decodedString1 = new String(encodedBytes1, StandardCharsets.ISO_8859_1);
System.out.println("Decoded String: " + decodedString1);
byte[] encodedBytes2 = {72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 32, -128}; // Hello, World! €
String decodedString2 = new String(encodedBytes2, StandardCharsets.ISO_8859_1);
System.out.println("Decoded String: " + decodedString2);
}
}
Last updated