UTF 8字符的Base64解码并打印
Base64 Decoding of UTF 8 character and printing it
我有以 Base64 编码的 UTF8 字符。我正在解码它并尝试打印 it.But 它只打印它的十六进制值而不是 UTF-8 字符串。
我尝试过的事情
1:我已经验证了字符是在线解码器,它告诉我我得到的字符串格式正确:
https://www.base64decode.org/
2: System.getProperty("file.encoding") 也是UTF8
def main(args: Array[String]): Unit = {
println("Hello, world!")
val sd = Base64.getDecoder.decode("7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY")
println(System.getProperty("file.encoding"))
println(sd.toString())
val sb = new StringBuffer
var i:Int=0
while(i<sd.length){
sb.append("%02X".format(sd(i) & 0xff))
i=i+1
}
println(sb)
}
我在这方面缺少什么?
所需的实际字符串如下:
수진수진수진수진수진수진수진수진수
"%02X".format(sd(i) & 0xff)
中的X
指定大写十六进制。尝试 %s
获取 UTF-8 字符串。
为什么不简单地使用 new String(sd, "UTF-8")
,这将 return 您的角色。在我的机器上工作,结果:수진수진수진수진수진수진수진수진수
我有以 Base64 编码的 UTF8 字符。我正在解码它并尝试打印 it.But 它只打印它的十六进制值而不是 UTF-8 字符串。
我尝试过的事情
1:我已经验证了字符是在线解码器,它告诉我我得到的字符串格式正确: https://www.base64decode.org/
2: System.getProperty("file.encoding") 也是UTF8
def main(args: Array[String]): Unit = {
println("Hello, world!")
val sd = Base64.getDecoder.decode("7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY7KeE7IiY")
println(System.getProperty("file.encoding"))
println(sd.toString())
val sb = new StringBuffer
var i:Int=0
while(i<sd.length){
sb.append("%02X".format(sd(i) & 0xff))
i=i+1
}
println(sb)
}
我在这方面缺少什么? 所需的实际字符串如下:
수진수진수진수진수진수진수진수진수
"%02X".format(sd(i) & 0xff)
中的X
指定大写十六进制。尝试 %s
获取 UTF-8 字符串。
为什么不简单地使用 new String(sd, "UTF-8")
,这将 return 您的角色。在我的机器上工作,结果:수진수진수진수진수진수진수진수진수