从XML中读取图片并生成

    技术2022-05-20  43

    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();  }

     }}

     


    最新回复(0)