你好,游客 登录 注册 搜索
背景:
阅读新闻

Android下实现电话号码归属地的查询

[日期:2011-08-22] 来源:Linux社区  作者:kesenhoo [字体:大 中 小]
 
  1. /** 
  2.  * 上传文件 
  3.  */  
  4. public class FormFile   
  5. {  
  6.     /* 上传文件的数据 */  
  7.     private byte[] data;  
  8.     private InputStream inStream;  
  9.     private File file;  
  10.     /* 文件名称 */  
  11.     private String filname;  
  12.     /* 请求参数名称*/  
  13.     private String parameterName;  
  14.     /* 内容类型 */  
  15.     private String contentType = "application/octet-stream";  
  16.       
  17.     public FormFile(String filname, byte[] data, String parameterName, String contentType)   
  18.     {  
  19.         this.data = data;  
  20.         this.filname = filname;  
  21.         this.parameterName = parameterName;  
  22.         if(contentType!=null) this.contentType = contentType;  
  23.     }  
  24.       
  25.     public FormFile(String filname, File file, String parameterName, String contentType)  
  26.     {  
  27.         this.filname = filname;  
  28.         this.parameterName = parameterName;  
  29.         this.file = file;  
  30.         try   
  31.         {  
  32.             this.inStream = new FileInputStream(file);  
  33.         }   
  34.         catch (FileNotFoundException e)   
  35.         {  
  36.             e.printStackTrace();  
  37.         }  
  38.         if(contentType!=null) this.contentType = contentType;  
  39.     }  
  40.       
  41.     public File getFile()   
  42.     {  
  43.         return file;  
  44.     }  
  45.     public InputStream getInStream()   
  46.     {  
  47.         return inStream;  
  48.     }  
  49.     public byte[] getData()   
  50.     {  
  51.         return data;  
  52.     }  
  53.     public String getFilname()   
  54.     {  
  55.         return filname;  
  56.     }  
  57.     public void setFilname(String filname)  
  58.     {  
  59.         this.filname = filname;  
  60.     }  
  61.     public String getParameterName()   
  62.     {  
  63.         return parameterName;  
  64.     }  
  65.     public void setParameterName(String parameterName)   
  66.     {  
  67.         this.parameterName = parameterName;  
  68.     }  
  69.     public String getContentType()   
  70.     {  
  71.         return contentType;  
  72.     }  
  73.     public void setContentType(String contentType)   
  74.     {  
  75.         this.contentType = contentType;  
  76.     }     
  77. }   

 
  1. public class StreamTool   
  2. {  
  3.     /** 
  4.      * 从输入流读取数据 
  5.      * @param inStream 
  6.      * @return 
  7.      * @throws Exception 
  8.      */  
  9.     public static byte[] readInputStream(InputStream inStream) throws Exception  
  10.     {  
  11.         ByteArrayOutputStream outSteam = new ByteArrayOutputStream();  
  12.         byte[] buffer = new byte[1024];  
  13.         int len = 0;  
  14.         while( (len = inStream.read(buffer)) !=-1 )  
  15.         {  
  16.             outSteam.write(buffer, 0, len);  
  17.         }  
  18.         outSteam.close();  
  19.         inStream.close();  
  20.         return outSteam.toByteArray();  
  21.     }  
  22. }   

4.程序运行效果:

linux
相关资讯       Android开发 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* ql6099 发表于 2011/12/1 15:33:39
使用webxml的soap方式:mobilesoap.xml在src目录下
这步该怎么做?