image
读写本地图片
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) { }
}
}
file
读写本地文件