ITeye博客

将文件变成字符串,再还原成文件

yl23250 · 2013-12-25 08:40 · java String · 编程语言 · Markdown


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 开发会用到,记一笔

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。