java从服务器复制文件到本地服务器

来源:互联网 发布:电钢琴 手感 知乎 编辑:程序博客网 时间:2024/06/03 21:21
URL url=new URL("服务器的地址:http://127.0.0.1:8080/demo"+"文件的目录地址:/backstage/upload"+"文件名与地址这里我是从服务器的数据库读出来的斜杠替换了一下:"tteststudentform.getStuimage().replace('\\','/'));HttpURLConnection connection=(HttpURLConnection) url.openConnection();BufferedInputStream bis=new BufferedInputStream(connection.getInputStream());BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(request.getSession().getServletContext().getRealPath("/backstage/upload"+tteststudentform.getStuimage())));int i=0;byte[]b=new byte[4096]; while ((i=bis.read(b))!=-1){     bos.write(b,0,i);    }bis.close();bos.close();
原创粉丝点击