将文件变成字符串,再还原成文件
byte[] sfile = getBytes("D:\\4.png");
Base64 base64 = new Base64();
byte[] a=base64.encode(sfile);
try {
String str = new String(a,"utf-8");
System.out.println("字符串长度:"+str.length());
byte[] xml=str.getBytes("UTF-8");
byte[] b=base64.decode(xml);
setFile(b, "c:\\", "4.png");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
转载:http://www.oschina.net/code/snippet_54124_27505
觉得web 开发会用到,记一笔