| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2268 人关注过本帖
标题:用C#写web service接收远程安卓前台图片传送然后存储在本地磁盘,打开磁盘文 ...
只看楼主 加入收藏
zhaohaobo
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-19
收藏
 问题点数:0 回复次数:0 
用C#写web service接收远程安卓前台图片传送然后存储在本地磁盘,打开磁盘文件能浏览传送的图片
public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
testUpload("/mnt/sdcard/img.jpg");
}

public static byte[] readStream(InputStream inStream) throws Exception {   
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();   
  System.out.println("------>byte[] readStream(InputStream inStream)");
  byte[] buffer = new byte[1024*4];   
  int len = -1;   
  while ((len = inStream.read(buffer)) != -1) {   
  outStream.write(buffer, 0, len);   
  }   
   
  outStream.close();   
  inStream.close();   
  return outStream.toByteArray();  
  }

  //上传方法
  public void testUpload(String path){   
  try{   
  File file = new File(path); //path是路径
  FileInputStream fis = new FileInputStream(file);  
  // 对文件进行类型转换
  System.out.println("FileInputStream--->currentpath"+path+"\n" );
  byte[] fileStream = readStream(fis);
  
  // 问题是现在这个 fileStream没有东西 ,出来异常了
 // 08-18 02:37:07.630: WARN/System.err(1846): java.lang.RuntimeException: Cannot serialize: [B@44efa1b8
 // fileStream输出的是这个---》[B@44efa1b8
  System.out.println("dong+++++++++"+fileStream);
  System.out.println("fileStream.length"+fileStream.length);  
  String SavePath ="f://picture";
  String FileName = "img.jpg";
  UpLoadFile(fileStream);
// String SavePath ="/mnt/sdcard/img.jpg";
// System.out.println("调用webservice 完成了 ");
// Log.i("fileStream", "start");   
// File f=new File(SavePath);
// if(f.exists())
// {
// f.createNewFile();
// }
// witeStream(fileStream,f);
  // fis.close();   
  }catch(Exception e){   
  e.printStackTrace();   
  }   
  }   
 public static boolean UpLoadFile(byte[] fileStream) throws Exception {   
  // boolean ret = false;
  System.out.println("WebService_Login.uploadfile");
  SoapObject soapObject = new SoapObject("http://, "UploadFile");   
  System.out.println("fileStream >>>>"+fileStream);
  soapObject.addProperty("fs",fileStream); //参数1 文件字符数组
  //soapObject.addProperty ("fs",new String(fileStream,"UTF-8"));
  // soapObject.addProperty("SavePath", SavePath); //保存路径
  // soapObject.addProperty("FileName", FileName); //参数2 文件字符串   
  // System.out.println("接口连接完成"+"fileStream---->"+FileName);
  SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(   
  SoapEnvelope.VER11);   
  envelope.bodyOut = soapObject;   
  HttpTransportSE httpTranstation = new HttpTransportSE("http://192.168.2.150/Service.asmx");  
  try {   
  httpTranstation.call(null, envelope);   
  Object result = envelope.getResponse();   
  Log.i("uploadfile", result.toString());   
  } catch (IOException e) {   
  e.printStackTrace();   
  } catch (XmlPullParserException e){
  e.printStackTrace();
  }
  return false;   
  }
        
//上传文件代码
  public static void witeStream(byte[] fileStream,File file) throws Exception {   
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();  
  FileOutputStream fout=new FileOutputStream(file);
  System.out.println("------>byte[] readStream(InputStream inStream)");
  fout.write(fileStream);   
  outStream.close();   
  }

}

以上是前台安卓端的代码,现在需要用用C#写web service接收安卓前台图片传送然后存储在本地磁盘,打开磁盘文件能浏览传送的图片,求高手看看以上代码是否正确,写写web service,要用C#写,谢谢谢!!
 
 
 
 
搜索更多相关主题的帖子: 图片 存储 service 本地磁盘 public 
2012-08-19 09:46
快速回复:用C#写web service接收远程安卓前台图片传送然后存储在本地磁盘,打开 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023349 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved