Converting byte array to String (Java)

前端 未结 7 1022
不知归路
不知归路 2020-11-28 06:29

I\'m writing a web application in Google app Engine. It allows people to basically edit html code that gets stored as an .html file in the blobstore.

I\

7条回答
  •  醉梦人生
    2020-11-28 07:04

    Java 7 and above

    You can also pass your desired encoding to the String constructor as a Charset constant from StandardCharsets. This may be safer than passing the encoding as a String, as suggested in the other answers.

    For example, for UTF-8 encoding

    String bytesAsString = new String(bytes, StandardCharsets.UTF_8);
    

提交回复
热议问题