`
hufeng
  • 浏览: 101202 次
  • 性别: Icon_minigender_1
  • 来自: 江西
社区版块
存档分类
最新评论

Webservice XFire 客户端上传文件

 
阅读更多


如果是XML文件,我们可以协议客户端请求时将XML信息组织成String ,服务器端返回的String 再用dom4j工具解析成XML。

如果是大型文件,在这里提供一种方式实现文件的上传。

							byte tempBype[] = new byte[100*1024];
												FileInputStream in = new FileInputStream(file);

												int cnt = -999;
												while(true){
													cnt = in.read(tempBype);
													String tempBase ="";
													writeLogger("发送请求数据==========="+ cnt);
													if(cnt != -1){
														tempBase = Base64.encode(tempBype);	
													}
													writeLogger("1发送请求数据==========="+ cnt);
													result1 = port.receiveTCDatasetFile(file.getName(), tempBase, cnt);
													if(cnt==-1)break;
												}

 2.服务器端接收

 

	//filename PR-000023.pdf buffSize 1MB offset -1表示结束

	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){//表示传递完成
				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";
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics