如何在java中将字节数组转换为字符串 [英] How to convert byte array to string in java

查看:721
本文介绍了如何在java中将字节数组转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

  byte  [] b =  new   byte  [ 5 ]; 
b [ 0 ] = 97 ;
b [ 1 ] = -68;
b [ 3 ] = 4 ;


系统。 out .println(b, < span class =code-string> ISO-8859-1);

不打印任何内容 for 4

在Linux中,它的显示框;请尽快帮助。

我尝试过:

系统。 out .println(b, ISO-8859-1);
这已经 -68;但不是 4 ;

解决方案

代码点4不是可打印字符,而是控制字符。由实现来定义打印的内容(没有任何东西,一个像空格或盒子一样的地方,或以某种方式解释它)。



另请参阅传输结束字符 - 维基百科,免费的百科全书 [ ^ ]

I have code like this:

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;

解决方案

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[^].


这篇关于如何在java中将字节数组转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆