Click here to Skip to main content
15,072,776 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have code like this:
C#
byte[] b = new byte[5];
    b[0] = 97;
    b[1] = -68;
    b[3] = 4;


System.out.println (b, "ISO-8859-1");

this is not printing anything for 4.

In Linux, its showing boxes; Please help ASAP.

What I have tried:

System.out.println (b, "ISO-8859-1");
 This has worked for -68; but not for 4;
Posted
Updated 26-Apr-16 0:08am
Comments
Patrice T 26-Apr-16 6:03am
   
What about showing a snipset of code ?

1 solution

The code point 4 is not a printable character but a control character. It is up to the implementation to define what is printed (nothing, a place holding character like space or a box, or interpreting it in some way).

See also End-of-Transmission character - Wikipedia, the free encyclopedia[^].
   
Comments
Sergey Alexandrovich Kryukov 26-Apr-16 10:35am
   
5ed. I would also add that 2 bytes in the array are not initialized.
—SA
Jochen Arndt 26-Apr-16 11:36am
   
Thank you (also for pointing out the obviously missing initialization).

I'm not so familiar with Java but I think the array must be NULL terminated and there is no overloaded println() version that accepts an encoding string as second parameter.
Sergey Alexandrovich Kryukov 26-Apr-16 13:03pm
   
In an array? Why? No, never; it would not make any sense. I would note that the null-terminated string was the most disastrous "invention" in all the history of computing.
—SA
Jochen Arndt 26-Apr-16 13:07pm
   
Oops. You are right; the size is tracked. Too much C recently.
Sergey Alexandrovich Kryukov 26-Apr-16 13:14pm
   
That certainly can be damaging... :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900