Android 把文件转换成字符流

来源:互联网 发布:java简易订餐系统 编辑:程序博客网 时间:2024/06/07 13:37
 /**     * 这个是把文件变成二进制流     *     * @param imagepath     * @return     * @throws Exception     */    public static byte[] readStream(String imagepath) throws Exception {        FileInputStream fs = new FileInputStream(imagepath);        ByteArrayOutputStream outStream = new ByteArrayOutputStream();        byte[] buffer = new byte[1024];        int len = 0;        while (-1 != (len = fs.read(buffer))) {            outStream.write(buffer, 0, len);        }        outStream.close();        fs.close();        return outStream.toByteArray();    }

原创粉丝点击