您的位置:首页 > 其它

从XML中读取图片并生成

2011-04-15 16:33 218 查看
package com.neusoft.zzn;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import sun.misc.BASE64Decoder;

/**
* 从XML文件中读取图片,并生成图片
*
* @author 张志南 zhangzhinan@neusoft.com
*
*/
public class XmlToImg {
public static void main(String[] args) {
File f = new File("C://lexus.xml");
SAXReader reader = new SAXReader();
try {
Document doc = reader.read(f);
Element root = doc.getRootElement();
Element image = (Element) root.selectSingleNode("imageData");
String s_data = image.getText();
BASE64Decoder decoder = new BASE64Decoder();
byte[] data = decoder.decodeBuffer(s_data);
FileOutputStream fos = new FileOutputStream("C://test_lexus.jpg");
fos.write(data);
fos.flush();
fos.close();
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: