How to convert a Java String to an ASCII byte array?

后端 未结 10 511
心在旅途
心在旅途 2020-12-01 04:28

How to convert a Java String to an ASCII byte array?

10条回答
  •  天涯浪人
    2020-12-01 04:32

    I found the solution. Actually Base64 class is not available in Android. Link is given below for more information.

    byte[] byteArray;                                                  
         byteArray= json.getBytes(StandardCharsets.US_ASCII);
        String encoded=Base64.encodeBytes(byteArray);
        userLogin(encoded);
    

    Here is the link for Base64 class: http://androidcodemonkey.blogspot.com/2010/03/how-to-base64-encode-decode-android.html

提交回复
热议问题