Example usage for android.util Base64 encodeToString

List of usage examples for android.util Base64 encodeToString

Introduction

In this page you can find the example usage for android.util Base64 encodeToString.

Prototype

public static String encodeToString(byte[] input, int offset, int len, int flags) 

Source Link

Document

Base64-encode the given data and return a newly allocated String with the result.

Usage

From source file:com.sogrey.sinaweibo.utils.FileUtil.java

/**
 * ?Base64/*from   www.  j a  va2  s  . c  om*/
 * 
 * @author Sogrey
 * @date 2015723
 * @param path
 * @return
 */
public static String getBase64FromPath(String path) {
    String base64 = "";
    try {
        File file = new File(path);
        byte[] buffer = new byte[(int) file.length() + 100];
        @SuppressWarnings("resource")
        int length = new FileInputStream(file).read(buffer);
        base64 = Base64.encodeToString(buffer, 0, length, Base64.DEFAULT);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return base64;
}