Byte array to String and back.. issues with -127

前端 未结 4 1754
野的像风
野的像风 2020-12-08 14:20

In the following:

 scala> (new String(Array[Byte](1, 2, 3, -1, -2, -127))).getBytes
 res12: Array[Byte] = Array(1, 2, 3, -1, -2, 63)

why

4条回答
  •  被撕碎了的回忆
    2020-12-08 14:32

    StringOps has a method getBytes, I think that is probably what one actually wants for converting String to Array[Byte]

    http://www.scala-lang.org/api/2.10.2/index.html#scala.collection.immutable.StringOps

提交回复
热议问题