/**xml * String类型转为xml */ SAXReader saxReader = new SAXReader(); org.dom4j.Document document; document = saxReader.read(new ByteArrayInputStream(xml.getBytes())); org.dom4j.Element incomingForm = document.getRootElement(); /** * 创建xml文件 */ OutputFormat format= OutputFormat.createPrettyPrint();//美化格式 format.setEncoding("UTF-8");//设置字符编码 XMLWriter write = new XMLWriter(new FileWriter(new File("src/createhouse.xml")),format); write.write(incomingForm); write.flush(); write.close(); System.out.println("创建createhouse.xml完毕!"); 服务端接收string类型 生成xml文件 服务Element housesub1=item.getChild("housePictureslist").getChild("housePicture").getChild("housePicInfo"); String housePic=housesub1.getText(); byte[] imgByte = hex2byte(housePic); InputStream in = new ByteArrayInputStream(imgByte); byte[] b = new byte[1024]; FileOutputStream fos=new FileOutputStream("WebRoot/upload/pictures/house/"+housePicTimeName+".jpg"); int nRead1 = 0; while( ( nRead1 = in.read(b) ) != -1 ){ fos.write( b, 0, nRead1 ); } fos.close(); 服务端读取生成的xml里面图片信息 生成图片 File file=new File("WebRoot/upload/pictures/house/" + housePic.getPicTimeName()); System.out.println(file+"图片路径"); if(file.exists() && file.isFile()) file.delete(); housePic是根据某个ID查出的那条图片信息 删除图片 public static byte[] hex2byte(String str) { if (str == null) return null; str = str.trim(); int len = str.length(); if (len == 0 || len % 2 == 1) return null; byte[] b = new byte[len / 2]; try { for (int i = 0; i < str.length(); i += 2) { b[i / 2] = (byte) Integer.decode("0X" + str.substring(i, i + 2)).intValue(); } return b; } catch (Exception e) { return null; } }