If it is an XML file, we can organize the XML information into a String when the client requests it, and then use the dom4j tool to parse the String returned by the server into XML.
If it is a large file, here is a way to upload the file.
byte tempBype[] = new byte[100*1024]; FileInputStream in = new FileInputStream(file); int cnt = -999; while(true){ cnt = in.read(tempBype); String tempBase =""; writeLogger("Send request data==========="+ cnt); if(cnt != -1){ tempBase = Base64.encode(tempBype); } writeLogger("1 send request data==========="+ cnt); result1 = port.receiveTCDatasetFile(file.getName(), tempBase, cnt); if(cnt==-1)break; }
2. Server-side reception
//filename PR-000023.pdf buffSize 1MB offset -1 means end public String receiveTCDatasetFile(String fileName, String buffStr,int offset) { String strTmpDirPath ="C:\\service\\"+fileName; File file = new File(strTmpDirPath); try { FileOutputStream fos = new FileOutputStream(file,true); if(offset==-1){//Indicates that the transfer is complete fos.close();return "yes"; } byte[] buffSize = Base64.decode(buffStr); int size=buffSize.length; fos.write(buffSize, 0, size); } catch (FileNotFoundException e) { e.printStackTrace (); } catch (IOException e) { e.printStackTrace (); } return "no"; }