通过一个url把文件下载
保存到d盘下如果用java代码实现

解决方案 »

  1.   

    如果是在页面上,那直接<a href="">,看浏览器对文件的支持情况,可以直接在浏览器打开或者下载。
    如果是在代码层面,那就用httpClient下载文件到你想保存的地方吧
    public File fileDownLoad(String filePath)
    {
    HttpUriRequest httpUriRequest = new HttpGet(filePath); String upload = TaskServiceImpl.class.getResource("/").toString().replace("file:", ""); upload = upload.substring(0, upload.indexOf("WEB-INF")) + "upload"; File file = new File(upload); if (file.isFile() || !file.exists())
    {
    file.mkdirs();
    } file = new File(file + File.separator + fileUrl.substring(filePath.lastIndexOf("/")));
    logger.info("下载文件到路径{}下", file.getAbsolutePath());
    try
    {
    HttpResponse remoteResponse = this.httpClient.execute(httpUriRequest); HttpEntity entity = remoteResponse.getEntity(); InputStream is = entity.getContent(); BufferedOutputStream write = new BufferedOutputStream(new FileOutputStream(file)); int nextChar;
    while ((nextChar = is.read()) != -1)
    {
    write.write(nextChar);
    } is.close(); write.flush(); write.close(); logger.info("文件下载完成,文件大小为{}", file.length()); return file; } catch (Exception e)
    {
    e.printStackTrace();
    logger.warn("下载文件失败{}", e.toString());
    return null;
    }
    }
    给你个下载的示例吧