Karam Abdullah
Karam Abdullah

Reputation: 45

Base64 encoding issue in Java

I have coded the following code to encode the byte[] str.

Byte[] str; 
Byte[] encoded=Base64.encodeToString(str); 

But Base64 word is not defined

I tried base64.encode() & base64.getEncoder()

I found a defined statement But I don't know how to use it:

byte[] encoded=Base64.encoder() 

How to use it? Or how can I encode a string or byte[] with or without libraries.

Upvotes: 1

Views: 171

Answers (1)

Eklavya
Eklavya

Reputation: 18430

Import Base64 as android.util.Base64

encodeToString takes byte array and return String.

String encoded=Base64.encodeToString(byteArray); 

Details about Base64.encodeToString here

Upvotes: 1

Related Questions