public static String base(String img,String path){
String name = null;
if (!"".equals(img)) {
if(img!=null){
BASE64Decoder decoder=new BASE64Decoder();
try
{
//Base64解码
byte[] b = decoder.decodeBuffer(img);
for(int j=0;j<b.length;++j)
{
if(b[j]<0)
{//调整异常数据
b[j]+=256;
}
}
name = abc.getCurrTime() + new Random().nextInt(1000)
+ ".jpg";
File newFile=new File(filedir +path);
if (!newFile.exists()) {
newFile.mkdirs();
}
OutputStream out = new FileOutputStream(filedir +path+name);
out.write(b);
out.flush();
out.close();
}catch (Exception e){
}
}
}
return name;
}
filedir是静态设置的路径。
path记得斜杠要打完整