标签:trace string null available size get rac ace nts
读写本地图片
public static String saveImgaeToLocal(String path, byte[] imgdata) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream(path);
os.write(imgdata, 0, imgdata.length);
os.flush();
} catch (Exception e) { return e.getMessage(); } finally {
if (os != null) { os.close(); }
}
return "";
}
public static String readImageFromLocal(String path) {
String data = "";
DataInputStream dataInputStream = null;
try {
dataInputStream = new DataInputStream(new FileInputStream(path));
byte[] b = new byte[dataInputStream.available()];//创建一个字节数组,长度等于二进制图片的返回的实际字节数
dataInputStream.read(b);//读取图片信息放入这个b数组
return Base64Util.encode(b);
} catch (IOException e) { e.printStackTrace(); } finally {
try {
if (null != dataInputStream) { dataInputStream.close();//关闭流 }
} catch (IOException e) { }
}
}
读写本地文件
标签:trace string null available size get rac ace nts
原文地址:https://www.cnblogs.com/wjcx-sqh/p/13439097.html