---
title: "将文件变成字符串，再还原成文件"
author: "yl23250"
date: "2013-12-25T08:40:37Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2013-12-25T08:40:37Z"
id: 1995112
url: "https://yl23250.iteye.com/blog/1995112"
---

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