为了账号安全,请及时绑定邮箱和手机立即绑定

Java从服务器端下载文件保存到本地,不是下载的图片?

Java从服务器端下载文件保存到本地,不是下载的图片?

一只斗牛犬 2019-03-22 18:15:58
public static void downloadFile(String urlPath, String filePath) throws IOException {        URL url = new URL(urlPath);        String name = urlPath.substring(urlPath.lastIndexOf("=")+1);        String filePaths = filePath+"/"+name;        File dirFile = new File(filePath);        if (!dirFile.exists()) {            dirFile.mkdir();        }        URLConnection connection = url.openConnection();        InputStream in = connection.getInputStream();        FileOutputStream os = new FileOutputStream(filePaths);        byte[] buffer = new byte[4 * 1024];        int read;        while ((read = in.read(buffer)) > 0) {            os.write(buffer, 0, read);        }        os.close();        in.close();    }    public static void main(String[] args) {        String urlPath = "http://10.192.32.111:80/production-jcw/getDownload.do?fileName=49e23d3a-5e11-432d-9f33-91c93130b37b.dwg";        String filePath = "C:/Users/MrLi/Desktop/";        try {            downloadFile(urlPath, filePath);            System.out.println("下载成功");        } catch (IOException e) {            e.printStackTrace();            System.out.println("下载失败");        }    }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 451 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号