I have string which contains null character ie \0
. How can I print the whole string in java?
String s = new String("abc\u0000def");
System.out.println(s.length());
System.out.println(s);
Output on eclipse console:
7
abc
Length is that of complete string, but how can I print the whole string?
UPDATE: I am using
Eclipse Helios Service Release 2
Java 1.6
7<nl>abc def
- on what system, and on which console, did you start the program? – Abdiasabc def
. What else do you expect it to print? (There is no space actually between abc & def, its a null char there, but it prints though) – Nephology\u0000
in output? – Monosepalousabc def
as output or do you literally wantabc\u0000def
? – Pessimist