android File 转成 byte[]

来源:互联网 发布:淘宝网购物商城首页 编辑:程序博客网 时间:2024/06/05 15:18

说明:android File 转成 byte[]

代码:

package briefer.tutu.utils;import java.io.Closeable;import java.io.File;import java.io.RandomAccessFile;/** * Created by zst on 2017/4/11. */public class FileUtil {    //file文件读取成byte[]    public static byte[] readFile(File file) {        RandomAccessFile rf = null;        byte[] data = null;        try {            rf = new RandomAccessFile(file, "r");            data = new byte[(int) rf.length()];            rf.readFully(data);        } catch (Exception exception) {            exception.printStackTrace();        } finally {            closeQuietly(rf);        }        return data;    }    //关闭读取file    public static void closeQuietly(Closeable closeable) {        try {            if (closeable != null) {                closeable.close();            }        } catch (Exception exception) {            exception.printStackTrace();        }    }}


0 0
原创粉丝点击