工具类--本地路径图片转字节

来源:互联网 发布:中国电视剧 国外 知乎 编辑:程序博客网 时间:2024/06/09 17:25

/**

 * 本地图片转byte类型

 * @param filePath 本地图片路径

 * @return

 */

    ​public static byte[] getBytes(String filePath) {

byte[] buffer = null;

try {

FileInputStream fis = new FileInputStream(filePath);

ByteArrayOutputStream bos = new ByteArrayOutputStream();

byte[] b = new byte[1024 * 10];

int n;

while ((n = fis.read(b)) != -1) {

bos.write(b, 0, n);

}

fis.close();

bos.close();

buffer = bos.toByteArray();

} catch (Exception e) {

e.printStackTrace();

return buffer;

}

0 0
原创粉丝点击