文件传输方式

来源:互联网 发布:淘宝服装抠图 编辑:程序博客网 时间:2024/05/16 00:58

1.    InputStream              OutPutStream

              可以将网络文件转成url,然后通过url.openConnection().getOutputStream(),获取对url的输出流,若对url要输入流,也可以url.getinputStream,格式为inputStream

              OutputStream os = url.openConnection().getOutputStream();
              InputStream is  = file.getInputStream();
              byte[] bytes = new byte[1024];
              int c;  
            // 暂未考虑中途终止的情况
            while ((c = is.read(bytes)) != -1) {
                 os.write(bytes, 0, c);
            }
           os.flush();
           is.close();
           os.close();

0 0
原创粉丝点击