当前位置:   article > 正文

Java系列之:byte[]和string之间的转换_byte[] 转string

byte[] 转string

Java系列之:byte[]和string之间的转换

一、String转化为byte[]

		//Original String
        String string = "hello world";

        //Convert to byte[]
        byte[] bytes = string.getBytes();

        System.out.println("bytes输出是:"+bytes);

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

输出如下所示:


bytes输出是:[B@43a0cee9
  • 1
  • 2

二、byte[]转化为string

        //Convert back to String
        //byte[] bytes
        String s = new String(bytes);

        //Check converted string against original String
        System.out.println("Decoded String : " + s);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

输出如下所示:

Decoded String : hello world
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/算法编织者/article/detail/61424
推荐阅读
相关标签
  

闽ICP备14008679号