运行main方法即可运行。。。

package com.Manage.control;import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;public class aatest {public static boolean saveUrlAs(String photoUrl, String fileName) {//此方法只能用户HTTP协议try {URL url = new URL(photoUrl);HttpURLConnection connection = (HttpURLConnection) url.openConnection();DataInputStream in = new DataInputStream(connection.getInputStream());DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));byte[] buffer = new byte[4096];int count = 0;while ((count = in.read(buffer)) > 0) {out.write(buffer, 0, count);}out.close();in.close();return true;}catch (Exception e) {return false;}}public String getDocumentAt(String urlString) {//此方法兼容HTTP和FTP协议StringBuffer document = new StringBuffer();try {URL url = new URL(urlString);URLConnection conn = url.openConnection();BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line = null;while ( (line = reader.readLine()) != null) {document.append(line + "/n");}reader.close();}catch (MalformedURLException e) {System.out.println("Unable to connect to URL: " + urlString);}catch (IOException e) {System.out.println("IOException when connecting to URL: " + urlString);}return document.toString();}public static void main(String[] args) {String photoUrl = "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png";                                  String fileName = photoUrl.substring(photoUrl.lastIndexOf("/"));String filePath = "d:/";boolean flag = saveUrlAs(photoUrl, filePath + fileName);System.out.println("Run ok!/n<BR>Get URL file " + flag);}
}

Java 从服务器下载文件到本地相关推荐

  1. ubuntu从本地上传文件到云服务器、从云服务器下载文件到本地的命令(亲测有效)

    1.ubuntu从本地上传文件到云服务器: sudo scp 本地文件路经 username@目标ip:目标路径 在本地打开终端,输入命令,如: scp ./localfile.txt usernam ...

  2. java使用ftp下载文件到本地(只是下载)

    1.添加依赖         camel-ftp依赖与commons-net依赖两者取其中一个即可         <dependency>             <groupId ...

  3. scp从服务器下载文件到本地或从本地上传文件到服务器

    1.从服务器下载文件 scp username@servername:/remote_path/filename ~/local_destination       2.上传本地文件到服务器   sc ...

  4. scp命令服务器下载文件到本地,scp命令linux拷贝文件到本地,服务器下载文件,scp命令拷贝文件,scp命令文件下载上传到服务器

    scp命令文件下载上传到服务器 # 服务器拷贝文件到本地 # # scp 服务器路径文件 本地路径文件 scp root@192.168.0.111:/tmp/test.sql D:/share/te ...

  5. java实现网上下载文件到本地

    思路: 要弄清网上下载文件的一些关键逻辑.我们要从网上获取信息,第一步必须要有网络连接(connection),接着是你要获取信息的路径(ResourceUrl),然后你要对获取到的信息的处理(pro ...

  6. 使用 scp 上传文件到远程服务器/从远程服务器下载文件到本地

    Intro wuyujin@ubuntu18:~/Desktop/project/网站部署$ whatis scp scp (1) - secure copy (remote file copy pr ...

  7. PHP网站从服务器下载文件到本地

    public function download_file(){//文件路径$fileurl = __DIR__."\\..\\success.txt";$filename = & ...

  8. PHP中curl使用案例(四)-- 从ftp服务器下载文件到本地

    //从FTP服务器下载一个文件到本地 //初始化 $curl = curl_init(); //设置被下载文件的url curl_setopt($curl, CURLOPT_URL,"ftp ...

  9. 常用的xshell命令之从本地上传文件和从服务器下载文件到本地

    借助XShell,使用linux命令sz可以很方便的将服务器上的文件下载到本地,使用rz命令则是把本地文件上传到服务器. 如果没有安装,需要执行:[cpp]yum install lrzsz[/cpp ...

最新文章

  1. 【Linux】一步一步学Linux——umask命令(111)
  2. 【WP 8.1开发】解决摄像头翻转问题(RuntimeApp篇)
  3. 微软SQL 报表服务的研究
  4. IPC 进程间通信方式——管道
  5. 深度操作系统 Deepin 15.11 发布
  6. ASP.NET的视图(Razor)循环产生html代码
  7. 为什么Byte类型的运算结果要用int类型来接收
  8. vscode 自定义全局代码片段
  9. win11如何退出磁贴桌面 Windows11退出磁贴桌面的设置方法
  10. air for android 使用ANE来获取安卓手机IMEI号
  11. 计算机控制系统第二章答案,计算机控制技术(第2版)部分课后题答案
  12. 【光纤通信】实验二、C语言实现HDB3编码
  13. python去重且顺序不变_python实现文本去重且不打乱原本顺序
  14. vnc支持用计算机民远程吗,VNC远程控制软件是什么?有没有更好的远程桌面控制解决方案?...
  15. C++ 使用技巧(持续更新)
  16. 1007 素数对猜想 (20 分)(打表)
  17. 易企秀 伪静态 linux,最新仿易企秀V15.1完整版开源版源码分享,修复采集功能,新增同行站模板采集功能等等...
  18. 超级服务器防熊系统教程,关于服务器防熊办法
  19. Android12 apk安装失败 安装包异常 安装包大小显示1k
  20. das dsadsa

热门文章

  1. linux下python安装包 3.7.1
  2. flyway和p6spy整合springboot
  3. Decorate和Proxy模式
  4. android 2.2 刷机,Android 2.2! 谷歌G1/Dream快速刷机教程
  5. vsphere安装教程
  6. Bezier曲线插值拟合
  7. Exception iterating responses: unhashable type: ‘list‘
  8. 为什么找不到工作的是你,技术差的还是你
  9. 服务器显示器超频,有关显示器超频的解决办法
  10. 库塔计算器是电子计算机吗,机械计算器“库塔”