- 浏览: 4911513 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (743)
- JAVA (44)
- JAVA 乔乐共享 (145)
- js (132)
- database (26)
- jQuery (46)
- velocity (16)
- Ubuntu (14)
- Grails (2)
- Groovy (6)
- xml (2)
- Spring (11)
- mysql (24)
- sqlserver (6)
- oracle (9)
- cmd (8)
- CSS (17)
- Linux (2)
- sqlite (4)
- php (11)
- json (2)
- laravel (2)
- html (3)
- 闲聊 (3)
- git (13)
- nodejs (25)
- angularjs (17)
- npm (8)
- bootstrap (4)
- mongodb (5)
- React (32)
- Crack (7)
- b (0)
- ES6 (2)
- webpack (3)
- Babel (1)
- Koa (1)
最新评论
-
taoshengyijiuzt:
感谢大佬!!!
JetBrains最新激活服务器(长期更新ing) -
masuweng:
激活码可以用
JetBrains最新激活服务器(长期更新ing) -
dusdong:
都失效了
JetBrains最新激活服务器(长期更新ing) -
追风筝的孩纸Zz:
dddddddddddddddd
js获取网页屏幕可见区域高度 -
自己811005:
88350bcf69dcfbda7f8a76a589d9054 ...
Js设置前端允许跨域请求后端API:Access-Control-Allow-Credentials
package com.proxy.util; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.params.CoreConnectionPNames; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.anxin.common.util.SSLUtil; /** * HTTP工具类. * * @author David.Huang */ public class HttpUtil { private static Logger log = LoggerFactory.getLogger(HttpUtil.class); /** 默认编码方式 -UTF8 */ private static final String DEFAULT_ENCODE = "utf-8"; // 信任所有站点 static { SSLUtil.trustAllHostnames(); SSLUtil.trustAllHttpsCertificates(); } /** * 构造方法 */ public HttpUtil() { // empty constructor for some tools that need an instance object of the // class } /** * GET请求, 结果以字符串形式返回. * * @param url * 请求地址 * @return 内容字符串 */ public static String getUrlAsString(String url) throws Exception { return getUrlAsString(url, null, DEFAULT_ENCODE); } /** * GET请求, 结果以字符串形式返回. * * @param url * 请求地址 * @param params * 请求参数 * @return 内容字符串 */ public static String getUrlAsString(String url, Map<String, String> params) throws Exception { return getUrlAsString(url, params, DEFAULT_ENCODE); } /** * GET请求, 结果以字符串形式返回. * * @param url * 请求地址 * @param params * 请求参数 * @param encode * 编码方式 * @return 内容字符串 */ public static String getUrlAsString(String url, Map<String, String> params, String encode) throws Exception { // 开始时间 long t1 = System.currentTimeMillis(); // 获得HttpGet对象 HttpGet httpGet = getHttpGet(url, params, encode); // 调试信息 log.debug("url:" + url); log.debug("params:" + params.toString()); log.debug("encode:" + encode); // 发送请求 String result = executeHttpRequest(httpGet, null); // 结束时间 long t2 = System.currentTimeMillis(); // 调试信息 log.debug("result:" + result); log.debug("consume time:" + ((t2 - t1))); // 返回结果 return result; } /** * POST请求, 结果以字符串形式返回. * * @param url * 请求地址 * @return 内容字符串 */ public static String postUrlAsString(String url) throws Exception { return postUrlAsString(url, null, null, null); } /** * POST请求, 结果以字符串形式返回. * * @param url * 请求地址 * @param params * 请求参数 * @return 内容字符串 */ public static String postUrlAsString(String url, Map<String, String> params) throws Exception { return postUrlAsString(url, params, null, null); } /** * POST请求, 结果以字符串形式返回. * * @param url * 请求地址 * @param params * 请求参数 * @param reqHeader * 请求头内容 * @return 内容字符串 * @throws Exception */ public static String postUrlAsString(String url, Map<String, String> params, Map<String, String> reqHeader) throws Exception { return postUrlAsString(url, params, reqHeader, null); } /** * POST请求, 结果以字符串形式返回. * * @param url * 请求地址 * @param params * 请求参数 * @param reqHeader * 请求头内容 * @param encode * 编码方式 * @return 内容字符串 * @throws Exception */ public static String postUrlAsString(String url, Map<String, String> params, Map<String, String> reqHeader, String encode) throws Exception { // 开始时间 long t1 = System.currentTimeMillis(); // 获得HttpPost对象 HttpPost httpPost = getHttpPost(url, params, encode); // 发送请求 String result = executeHttpRequest(httpPost, reqHeader); // 结束时间 long t2 = System.currentTimeMillis(); // 调试信息 log.debug("url:" + url); log.debug("params:" + params.toString()); log.debug("reqHeader:" + reqHeader); log.debug("encode:" + encode); log.debug("result:" + result); log.debug("consume time:" + ((t2 - t1))); // 返回结果 return result; } /** * 获得HttpGet对象 * * @param url * 请求地址 * @param params * 请求参数 * @param encode * 编码方式 * @return HttpGet对象 */ private static HttpGet getHttpGet(String url, Map<String, String> params, String encode) { StringBuffer buf = new StringBuffer(url); if (params != null) { // 地址增加?或者& String flag = (url.indexOf('?') == -1) ? "?" : "&"; // 添加参数 for (String name : params.keySet()) { buf.append(flag); buf.append(name); buf.append("="); try { String param = params.get(name); if (param == null) { param = ""; } buf.append(URLEncoder.encode(param, encode)); } catch (UnsupportedEncodingException e) { log.error("URLEncoder Error,encode=" + encode + ",param=" + params.get(name), e); } flag = "&"; } } HttpGet httpGet = new HttpGet(buf.toString()); return httpGet; } /** * 获得HttpPost对象 * * @param url * 请求地址 * @param params * 请求参数 * @param encode * 编码方式 * @return HttpPost对象 */ private static HttpPost getHttpPost(String url, Map<String, String> params, String encode) { HttpPost httpPost = new HttpPost(url); if (params != null) { List<NameValuePair> form = new ArrayList<NameValuePair>(); for (String name : params.keySet()) { form.add(new BasicNameValuePair(name, params.get(name))); } try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, encode); httpPost.setEntity(entity); } catch (UnsupportedEncodingException e) { log.error("UrlEncodedFormEntity Error,encode=" + encode + ",form=" + form, e); } } return httpPost; } /** * 执行HTTP请求 * * @param request * 请求对象 * @param reqHeader * 请求头信息 * @return 内容字符串 */ private static String executeHttpRequest(HttpUriRequest request, Map<String, String> reqHeader) throws Exception { HttpClient client = null; String result = null; try { // 创建HttpClient对象 client = new DefaultHttpClient(); // 设置连接超时时间 client.getParams().setParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, 60); // 设置Socket超时时间 client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 36600); // 设置请求头信息 if (reqHeader != null) { for (String name : reqHeader.keySet()) { request.addHeader(name, reqHeader.get(name)); } } // 获得返回结果 HttpResponse response = client.execute(request); // 如果成功 if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { result = EntityUtils.toString(response.getEntity()); } // 如果失败 else { StringBuffer errorMsg = new StringBuffer(); errorMsg.append("httpStatus:"); errorMsg.append(response.getStatusLine().getStatusCode()); errorMsg.append(response.getStatusLine().getReasonPhrase()); errorMsg.append(", Header: "); Header[] headers = response.getAllHeaders(); for (Header header : headers) { errorMsg.append(header.getName()); errorMsg.append(":"); errorMsg.append(header.getValue()); } log.error("HttpResonse Error:" + errorMsg); } } catch (Exception e) { log.error("http连接异常", e); throw new Exception("http连接异常"); } finally { try { client.getConnectionManager().shutdown(); } catch (Exception e) { log.error("finally HttpClient shutdown error", e); } } return result; } /** * 下载文件保存到本地 * * @param path * 文件保存位置 * @param url * 文件地址 * @throws IOException */ public static void downloadFile(String path, String url) throws IOException { log.debug("path:" + path); log.debug("url:" + url); HttpClient client = null; try { // 创建HttpClient对象 client = new DefaultHttpClient(); // 获得HttpGet对象 HttpGet httpGet = getHttpGet(url, null, null); // 发送请求获得返回结果 HttpResponse response = client.execute(httpGet); // 如果成功 if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { byte[] result = EntityUtils.toByteArray(response.getEntity()); BufferedOutputStream bw = null; try { // 创建文件对象 File f = new File(path); // 创建文件路径 if (!f.getParentFile().exists()) f.getParentFile().mkdirs(); // 写入文件 bw = new BufferedOutputStream(new FileOutputStream(path)); bw.write(result); } catch (Exception e) { log.error("保存文件错误,path=" + path + ",url=" + url, e); } finally { try { if (bw != null) bw.close(); } catch (Exception e) { log.error( "finally BufferedOutputStream shutdown close", e); } } } // 如果失败 else { StringBuffer errorMsg = new StringBuffer(); errorMsg.append("httpStatus:"); errorMsg.append(response.getStatusLine().getStatusCode()); errorMsg.append(response.getStatusLine().getReasonPhrase()); errorMsg.append(", Header: "); Header[] headers = response.getAllHeaders(); for (Header header : headers) { errorMsg.append(header.getName()); errorMsg.append(":"); errorMsg.append(header.getValue()); } log.error("HttpResonse Error:" + errorMsg); } } catch (ClientProtocolException e) { log.error("下载文件保存到本地,http连接异常,path=" + path + ",url=" + url, e); throw e; } catch (IOException e) { log.error("下载文件保存到本地,文件操作异常,path=" + path + ",url=" + url, e); throw e; } finally { try { client.getConnectionManager().shutdown(); } catch (Exception e) { log.error("finally HttpClient shutdown error", e); } } } public static void main(String[] args) throws IOException { // String result = getUrlAsString("http://www.gewara.com/"); // System.out.println(result); downloadFile("F:/logo3w.png", "http://www.google.com.hk/images/srpr/logo3w.png"); } }
评论
5 楼
yizhichao116
2016-09-01
byte[] result = EntityUtils.toByteArray(response.getEntity());
这边这样处理不太好吧,如果文件过大的时候。。。
这边这样处理不太好吧,如果文件过大的时候。。。
4 楼
ljlowkey
2015-07-17
大文件下载貌似很慢,求解
3 楼
zt307484565
2014-12-28
赞!好用。
2 楼
qiaolevip
2014-03-24
wangjieisjason1985 写道
你好,可否将你的代码共享全一些;wangjieisjason@163.com
import com.anxin.common.util.SSLUtil;
import com.anxin.common.util.SSLUtil;
package com.anxin.ssk.util; import java.security.GeneralSecurityException; import java.security.SecureRandom; import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; /** * This class provide various static methods that relax X509 certificate and hostname verification while using the SSL * over the HTTP protocol. * * @author Francis Labrie */ @SuppressWarnings("restriction") public final class SSLUtil { /** * Hostname verifier for the Sun's deprecated API. * * @deprecated see {@link #_hostnameVerifier}. */ private static com.sun.net.ssl.HostnameVerifier __hostnameVerifier; /** * Thrust managers for the Sun's deprecated API. * * @deprecated see {@link #_trustManagers}. */ private static com.sun.net.ssl.TrustManager[] __trustManagers; /** * Hostname verifier. */ private static HostnameVerifier _hostnameVerifier; /** * Thrust managers. */ private static TrustManager[] _trustManagers; /** * Set the default Hostname Verifier to an instance of a fake class that trust all hostnames. This method uses the * old deprecated API from the com.sun.ssl package. * * @deprecated see {@link #_trustAllHostnames()}. */ private static void __trustAllHostnames() { // Create a trust manager that does not validate certificate chains if (__hostnameVerifier == null) { __hostnameVerifier = new _FakeHostnameVerifier(); } // if // Install the all-trusting host name verifier com.sun.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(__hostnameVerifier); } // __trustAllHttpsCertificates /** * Set the default X509 Trust Manager to an instance of a fake class that trust all certificates, even the * self-signed ones. This method uses the old deprecated API from the com.sun.ssl package. * * @deprecated see {@link #_trustAllHttpsCertificates()}. */ private static void __trustAllHttpsCertificates() { com.sun.net.ssl.SSLContext context; // Create a trust manager that does not validate certificate chains if (__trustManagers == null) { __trustManagers = new com.sun.net.ssl.TrustManager[] { new _FakeX509TrustManager() }; } // if // Install the all-trusting trust manager try { context = com.sun.net.ssl.SSLContext.getInstance("SSL"); context.init(null, __trustManagers, new SecureRandom()); } catch (GeneralSecurityException gse) { throw new IllegalStateException(gse.getMessage()); } // catch com.sun.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); } // __trustAllHttpsCertificates /** * Return true if the protocol handler property java. protocol.handler.pkgs is set to the Sun's com.sun.net.ssl. * internal.www.protocol deprecated one, false otherwise. * * @return true if the protocol handler property is set to the Sun's deprecated one, false otherwise. */ private static boolean isDeprecatedSSLProtocol() { return ("com.sun.net.ssl.internal.www.protocol".equals(System.getProperty("java.protocol.handler.pkgs"))); } // isDeprecatedSSLProtocol /** * Set the default Hostname Verifier to an instance of a fake class that trust all hostnames. */ private static void _trustAllHostnames() { // Create a trust manager that does not validate certificate chains if (_hostnameVerifier == null) { _hostnameVerifier = new FakeHostnameVerifier(); } // if // Install the all-trusting host name verifier: HttpsURLConnection.setDefaultHostnameVerifier(_hostnameVerifier); } // _trustAllHttpsCertificates /** * Set the default X509 Trust Manager to an instance of a fake class that trust all certificates, even the * self-signed ones. */ private static void _trustAllHttpsCertificates() { SSLContext context; // Create a trust manager that does not validate certificate chains if (_trustManagers == null) { _trustManagers = new TrustManager[] { new FakeX509TrustManager() }; } // if // Install the all-trusting trust manager: try { context = SSLContext.getInstance("SSL"); context.init(null, _trustManagers, new SecureRandom()); } catch (GeneralSecurityException gse) { throw new IllegalStateException(gse.getMessage()); } // catch HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); } // _trustAllHttpsCertificates /** * Set the default Hostname Verifier to an instance of a fake class that trust all hostnames. */ public static void trustAllHostnames() { // Is the deprecated protocol setted? if (isDeprecatedSSLProtocol()) { __trustAllHostnames(); } else { _trustAllHostnames(); } // else } // trustAllHostnames /** * Set the default X509 Trust Manager to an instance of a fake class that trust all certificates, even the * self-signed ones. */ public static void trustAllHttpsCertificates() { // Is the deprecated protocol setted? if (isDeprecatedSSLProtocol()) { __trustAllHttpsCertificates(); } else { _trustAllHttpsCertificates(); } // else } // trustAllHttpsCertificates /** * This class implements a fake hostname verificator, trusting any host name. This class uses the old deprecated API * from the com.sun. ssl package. * * @author Francis Labrie * * @deprecated see {@link SSLUtil.FakeHostnameVerifier}. */ public static class _FakeHostnameVerifier implements com.sun.net.ssl.HostnameVerifier { /** * Always return true, indicating that the host name is an acceptable match with the server's authentication * scheme. * * @param hostname the host name. * @param session the SSL session used on the connection to host. * @return the true boolean value indicating the host name is trusted. */ public boolean verify(String hostname, String session) { return (true); } // verify } // _FakeHostnameVerifier /** * This class allow any X509 certificates to be used to authenticate the remote side of a secure socket, including * self-signed certificates. This class uses the old deprecated API from the com.sun.ssl package. * * @author Francis Labrie * * @deprecated see {@link SSLUtil.FakeX509TrustManager}. */ public static class _FakeX509TrustManager implements com.sun.net.ssl.X509TrustManager { /** * Empty array of certificate authority certificates. */ private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {}; /** * Always return true, trusting for client SSL chain peer certificate chain. * * @param chain the peer certificate chain. * @return the true boolean value indicating the chain is trusted. */ public boolean isClientTrusted(X509Certificate[] chain) { return (true); } // checkClientTrusted /** * Always return true, trusting for server SSL chain peer certificate chain. * * @param chain the peer certificate chain. * @return the true boolean value indicating the chain is trusted. */ public boolean isServerTrusted(X509Certificate[] chain) { return (true); } // checkServerTrusted /** * Return an empty array of certificate authority certificates which are trusted for authenticating peers. * * @return a empty array of issuer certificates. */ public X509Certificate[] getAcceptedIssuers() { return (_AcceptedIssuers); } // getAcceptedIssuers } // _FakeX509TrustManager /** * This class implements a fake hostname verificator, trusting any host name. * * @author Francis Labrie */ public static class FakeHostnameVerifier implements HostnameVerifier { /** * Always return true, indicating that the host name is an acceptable match with the server's authentication * scheme. * * @param hostname the host name. * @param session the SSL session used on the connection to host. * @return the true boolean value indicating the host name is trusted. */ public boolean verify(String hostname, javax.net.ssl.SSLSession session) { return (true); } // verify } // FakeHostnameVerifier /** * This class allow any X509 certificates to be used to authenticate the remote side of a secure socket, including * self-signed certificates. * * @author Francis Labrie */ public static class FakeX509TrustManager implements X509TrustManager { /** * Empty array of certificate authority certificates. */ private static final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {}; /** * Always trust for client SSL chain peer certificate chain with any authType authentication types. * * @param chain the peer certificate chain. * @param authType the authentication type based on the client certificate. */ public void checkClientTrusted(X509Certificate[] chain, String authType) { } // checkClientTrusted /** * Always trust for server SSL chain peer certificate chain with any authType exchange algorithm types. * * @param chain the peer certificate chain. * @param authType the key exchange algorithm used. */ public void checkServerTrusted(X509Certificate[] chain, String authType) { } // checkServerTrusted /** * Return an empty array of certificate authority certificates which are trusted for authenticating peers. * * @return a empty array of issuer certificates. */ public X509Certificate[] getAcceptedIssuers() { return (_AcceptedIssuers); } // getAcceptedIssuers } // FakeX509TrustManager } // SSLUtilities
1 楼
wangjieisjason1985
2014-03-21
你好,可否将你的代码共享全一些;wangjieisjason@163.com
import com.anxin.common.util.SSLUtil;
import com.anxin.common.util.SSLUtil;
发表评论
-
JAX-WS获取天气预报wsdl
2014-08-01 12:14 1539天气预报地址:http://www.webxml.com.c ... -
巴西世界杯期间,32支强队对战情况一览表
2014-07-07 15:53 810积分 A 巴西 7 墨西哥 ... -
Hp(中国上海)第一次电话面试
2014-07-07 13:45 1515时间:发简历的第二天 方式:电话面试 时长:25m 内 ... -
Java判断当前时间是否在两个时间段内
2014-04-11 18:59 24884// 播放时间段格式:0000-2359 String ... -
Java启动本机应用程序EXE的三种方式
2014-04-03 10:06 11420// 第一种方式:利用cmd方式 /** * ... -
ProcessBuilder实例启动一个新的应用程序
2014-04-03 10:01 1569/** * 启动应用程序 * * @pa ... -
Java判断应用程序启动状态并打开或关闭应用程序
2014-04-02 15:43 2039package com.anxin.ssk.util; ... -
Java cmd判断本地网络状态及强度
2014-04-02 14:06 1634package com.anxin.ssk.util; ... -
Java获取Set中第一个值
2014-03-18 16:21 23966Map<String, List<Cinema ... -
java取汉字拼音首字母含多音字及不常见的字
2014-03-13 11:25 10586package com.anxin.ssk.common; ... -
Java汉字区位码计算机对照表
2014-03-06 11:47 20897package com.anxin.ssk.common; ... -
java汉字转拼音或首字母,手写版非pinyin4j,可排除例外
2014-03-06 11:16 2168package com.anxin.ssk.common; ... -
JAVA调用spring注入class
2014-01-21 15:55 3854<?xml version="1.0&quo ... -
java.util.ConcurrentModificationException 原因及解决方案
2013-12-19 20:17 224612:13:30,822 [ERROR] 优惠券缓存 初始化 ... -
创建多人机票订单数据结构
2013-12-05 00:03 1741public AirplaneCreateOrderResu ... -
java断点续传原理总结
2013-10-18 13:36 1653断点续传总结 断点续传的原理: 断点续传的原理很简单,就 ... -
妙用分隔符分割循环数据
2013-08-14 10:08 1381public static void main(Strin ... -
spring还可以这样配置list对象
2013-05-24 16:12 2555// 配置内容 <entry key="s ... -
List<String>转换String[]或String
2013-05-10 15:52 1220List<String> strlist = ... -
Spring MVC 三种参数注入
2013-04-16 22:43 29551)参数注入第一种方法 <!-- xml服务 - ...
相关推荐
JAVA下载远程文件到本地的最精简代码,就一行代码,不信自己看,而且是官方提供,绝对适合你,一个远程URL,一个本地路径,文件就在你的电脑上了
综上所述,通过Java的HttpClient库,可以在Eclipse环境中编写程序,实现从指定URL下载文件到本地的功能。通过理解HttpClient的工作原理和提供的API,开发者可以构建出稳定、高效的文件下载解决方案。
在Java编程中,下载网络图片并将其保存到本地是一个常见的任务,特别是在开发涉及网页抓取、数据备份或者网络资源管理的项目中。这个过程通常包括以下几个步骤:建立网络连接、发送请求、接收响应数据以及将数据保存...
后端服务器(如Java Servlet或Spring MVC Controller)接收到请求后,可以使用前面提到的Java文件操作API处理上传的文件,并将其保存到服务器的指定位置。 对于文件下载,HTML中可以创建一个链接,指向服务器上的...
在Java编程语言中,我们可以利用HTTP协议来实现从网上下载文件到本地的功能。这个过程涉及到网络编程、IO流处理以及文件操作等知识点。下面将详细解释如何实现这一目标。 首先,我们需要了解HTTP协议,它是互联网上...
1. 一键批量下载:只需启动程序,即可自动遍历并下载M3U8文件列表中的全部TS片段,极大地提升了工作效率,省去手动逐个下载的繁琐过程。 2. 智能排序:根据M3U8文件的顺序逻辑,精确无误地将各个TS文件按序下载,...
本文档将详细介绍如何使用Java实现基于HTTP协议的本地文件下载功能。主要聚焦于通过文件名及文件的全路径来实现本地文件的下载。 #### 二、关键概念与技术点 ##### 2.1 HTTPServletResponse `HttpServletResponse...
在"云存储文件下载到本地java.zip"这个项目中,我们可以看到四个Java类文件:JDCloudFileUtil.java、HuaweiCloudFileUtil.java、TencentCloudFileUtil.java和AliCloudFileUtil.java。这些类是针对不同云服务商实现的...
在Java编程语言中,直接打开本地文件是一项基本但至关重要的任务。这主要涉及到I/O(输入/输出)操作,这是所有程序与外部世界交互的基础。本文将深入探讨如何使用Java来打开本地文件,包括HTML文件和文本文件。 ...
在Java编程语言中,FTP(File Transfer Protocol)文件上传和下载是常见的网络操作,用于在本地计算机和远程服务器之间交换文件。以下将详细介绍如何使用Java实现FTP文件上传和下载的步骤,以及涉及到的关键知识点。...
在Java开发中,将本地文件上传到阿里云OSS(Object Storage Service)是常见的操作,尤其在处理大数据存储和分发时。阿里云OSS提供了一种高效、安全且经济的云端存储解决方案。本篇文章将详细讲解如何使用Java SDK...
java生成excel并下载到本地(可选择保存路径),文件通过流的形式响应客户端浏览器下载到本地。
该方法会将服务器上的文件下载到本地。 ```java sftp.get(远程文件路径, 本地保存路径); ``` **删除Linux服务器文件** 删除文件可以使用`rm()`或`rmdir()`方法。前者用于删除单个文件,后者用于删除目录(如果...
在Java编程环境中,生成二维码并将其保存到本地是一项常见的任务,尤其在移动互联网应用、数据交换和物联网场景中。二维码(Quick Response Code)作为一种高效的信息载体,能够存储大量的文本、URL或其他数据,便于...
本文将详细介绍几种常用的Java文件下载方式,包括本地文件下载、网络文件下载以及支持断点续传的下载方式。 #### 1. 本地文件下载 本地文件下载主要涉及到读取本地文件并将其发送到客户端的过程。以下代码示例展示...
本文档主要介绍如何使用Java编程语言实现从网络上下载文件并将其保存至本地指定路径的功能,且在执行过程中不会弹出任何用户界面窗口。这种方法非常适合后台服务或自动化脚本场景。 #### 核心知识点详解 1. **URL...
本篇文章将详细探讨如何使用Java实现本地文件监听,并自动将其上传至服务器,以实现文件同步功能。 首先,让我们从“JAVA 监听文件夹变化”这个知识点开始。Java提供了一种称为`WatchService`的机制,它允许程序...
Java下载功能的实现有多种方式,一般来说可以分为三种:第一种是将要下载的内容写到本地目录,然后将目录返回给前端,利用a标签下载;第二种是本地不允许访问,挂载目录,使目录可以对外访问,同样的,把目录返给...
在本篇文章中,我们将详细介绍如何使用Java编程语言通过FTP(文件传输协议)实现文件的上传与下载功能,并能够将文件指定上传或下载到特定的服务器目录下。此方法已经过测试验证,能够满足基本的需求,并且代码易于...
综上所述,"java,jsp读取远程图片到本地服务器"涉及到的技术点包括Java和JSP的基础知识、HTTP通信、文件操作、HTML解析、在线编辑器集成以及性能优化等多个方面。理解并掌握这些知识点对于开发此类应用至关重要。