File f = new File("D://22.jpg"); FileInputStream fis = new FileInputStream(f); byte[] bytes = new byte[fis.available()]; fis.read(bytes); fis.close(); // 图片生成字符串 String houseImag = byte2hex(bytes); Element root = new Element("houselist"); Document doc = new Document(root); Element house = new Element("house"); Element housePictureslist = new Element("housePictureslist"); Element housePicture = new Element("housePicture"); housePicture.addContent(new Element("housePicInfo").setText(houseImag); housePictureslist.addContent(housePicture); house.addContent(housePictureslist); ByteArrayOutputStream byteRep = new ByteArrayOutputStream(); XMLOutputter docWriter = new XMLOutputter(); try { docWriter.output(doc, byteRep); } catch (Exception e) { e.printStackTrace(); } String strFromXml=byteRep.toString(); return strFromXml; } public static String byte2hex(byte[] b) // 二进制转字符串 { StringBuffer sb = new StringBuffer(); String stmp = ""; for (int n = 0; n < b.length; n++) { stmp = Integer.toHexString(b[n] & 0XFF); if (stmp.length() == 1) { sb.append("0" + stmp); } else { sb.append(stmp); } } return sb.toString(); 调用此方法生成String xml传送给服务端