package com.zjxt.demo.test;
import org.apache.commons.codec.binary.Base64;
import java.io.*;
/**
* @Author: heiheihaxi
* @Date: 2019/4/26 10:02
*/
public class Test26 {
public static void main(String[] args) {
File file=new File("C:\\Users\\zzh\\Desktop\\zciu2rebfbh.jpg");
InputStream is=null;
byte [] data=null;
try {
is=new FileInputStream(file);
data = new byte[is.available()];
is.read(data);
} catch (IOException e) {
e.printStackTrace();
}finally {
if (null!=data)
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String s =null;
if (null != data){
s = new String(Base64.encodeBase64(data));
}
byte[] bytes = Base64.decodeBase64(s);
OutputStream os = null;
try {
os = new FileOutputStream(new File("C:\\Users\\zzh\\Desktop\\zc2.jpg"));
if (null != bytes)
os.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}finally {
if (null!=os)
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}