Encode Base64 File - Blackberry / J2ME

I am trying to upload a file to an http server, but first I need to encode it in base64 format. How should I do it? I opened a connection to a file, but I do not know how to encode the file.

+3
source share
3 answers

Since BlackBerry is a J2ME environment, you cannot use regular J2SE clusters such as sun.misc.BASE64Encoder, but there is a native Base64OutputStream that should serve the same purpose. For more information, see Javadocs.

+3
source

See this java-me Base64 class for base64 encoding.

koders Java ME: Encode- Base64 JavaMe.

+3

If you do this in Java, you can use BASE64Encoder and write to a new encoded file:

import sun.misc.BASE64Encoder;

     public static void main(String[] args) throws Exception {

        File inputFile = new File(yourUnencodedFile);
        File outputFile = new File(yourEncodedFile);

        BASE64Encoder encoder = new BASE64Encoder();
        encoder.encode(
            new FileInputStream(inputFile),
            new FileOutputStream(outputFile)
        );

and then just use the encoded output file

-3
source

Source: https://habr.com/ru/post/1788375/


All Articles