开发者

Java "\u0001something" doesn't return expected results

I'm trying to put together a string that starts w开发者_如何学Cith the ascii "Start of Header" character (0x01). I did this on my home computer simple enough with:

String out = "\u0001this";
System.out.println(out);

prints a square to the terminal.. Copy and paste to hex editor and I have my 0x01;

Now at work.. I do the same thing but anything below 0x20 just prints 0x00 to the terminal. As soon as I do "\u0020" I get a space printed to output.. Any idea whats going on.


Might want to check what file encoding you are using, what charset your JVM runs under by default, etc. Different environments will likely have different settings.


This is almost surely a function of your terminal emulator or other program displaying what is written to standard out. This character is by definition non-printable, so what a terminal does to 'display' it likely varies. Some print a box, some a blank, some nothing.

If you are relying on how a non-printable character is printed, which isn't defined, maybe that is the issue? what problem does it cause?


Can you write this string directly to a file and open that file in the hex editor? By writing the text to the console and then relying on cut-and-paste to move the bytes to a different application, there are quite a few intermediate steps that could be messing with your data.

I suspect that your code is actually working but you're unintentionally obscuring your own (correct) results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜