java大数据的下载实现|用java实现文件的下载如何提高下载速度(非web开发)

Ⅰ java下载实现

简单的方法,就是直抄接把你的文件做成个超链接,点击超链接的时候就可以实现下载,就能实现像你说的这种会出现保存路径,用户选择路径后,按确定,就可以下载了:<a href="你文件的path">你的文件的名称</a> <!–文件的path可以使用相对路径–>复杂的方法,还是使用下载组件,然后在servlet中处理

Ⅱ Java 批量大文件上传下载如何实现

解决这种大文件上传不太可能用web上传的方式,只有自己开发插件或是当门客户端上传,或者用现有的ftp等。1)开发一个web插件。用于上传文件。2)开发一个FTP工具,不用web上传。3)用现有的FTP工具。下面是几款不错的插件,你可以试试:1)Jquery的uploadify插件。具体使用。你可以看帮助文档。

Ⅲ java如何实现文件上传和下载的功能

import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.jspsmart.upload.*;import net.sf.json.JSONObject;import action.StudentAction;public class UploadServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean result=true; SmartUpload mySmartUpload=new SmartUpload(); mySmartUpload.initialize(this.getServletConfig(), request,response); mySmartUpload.setTotalMaxFileSize(50*1024*1024);//大小限制 mySmartUpload.setAllowedFilesList("doc,docx");//后缀名限制 try { mySmartUpload.upload(); com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0); myFile.saveAs("/file/"+1+".doc");//保存目录 } catch (SmartUploadException e) { e.printStackTrace();result=false; } //*****************************// response.setContentType("text/html;charset=UTF-8"); response.setHeader("Cache-Control","no-cache"); PrintWriter out = response.getWriter(); out.print(result); out.flush(); out.close(); }}//我这是ajax方式的,不想这样,把//**********************//以下部分修改就行了//需要SmartUpload组件,去网上下个就行了,也有介绍的

Ⅳ 通过java实现文件下载

在jsp/servlet中断点/多线程下载文件<%@ page import="java.io.File" %><%@ page import="java.io.IOException" %><%@ page import="java.io.OutputStream" %><%@ page import="java.io.RandomAccessFile" %><%! public void downloadFile(HttpServletRequest request, HttpServletResponse response, File file) throws IOException { RandomAccessFile raf = new RandomAccessFile(file, "r"); java.io.FileInputStream fis = new java.io.FileInputStream(raf.getFD()); response.setHeader("Server", "www.trydone.com"); response.setHeader("Accept-Ranges", "bytes"); long pos = 0; long len; len = raf.length(); if (request.getHeader("Range") != null) { response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); pos = Long.parseLong(request.getHeader("Range") .replaceAll("bytes=", "") .replaceAll("-", "") ); } response.setHeader("Content-Length", Long.toString(len – pos)); if (pos != 0) { response.setHeader("Content-Range", new StringBuffer() .append("bytes ") .append(pos) .append("-") .append(Long.toString(len – 1)) .append("/") .append(len) .toString() ); } response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", new StringBuffer() .append("attachment;filename=\"") .append(file.getName()) .append("\"").toString()); raf.seek(pos); byte[] b = new byte[2048]; int i; OutputStream outs = response.getOutputStream(); while ((i = raf.read(b)) != -1) { outs.write(b, 0, i); } raf.close(); fis.close(); }%><% String filePath = request.getParameter("file"); filePath = application.getRealPath(filePath); File file = new File(filePath); downloadFile(request, response, file);%>是否可以解决您的问题?

Ⅳ 用java实现文件的下载,如何提高下载速度(非web开发)

下面贴出的代码是一个简单的读取远程文件保存到本地的实现,至于提高下载速度你可以利用多线程,具体可参考最下面的那个网址——import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.net.URL;public class DownloadTester { public static void main(String[] args) throws IOException { String urlStr = "http://img..com/img/logo-.gif"; String path = "D:/"; String name = urlStr.substring(urlStr.trim().lastIndexOf("/")); URL url = new URL(urlStr); InputStream in = url.openConnection().getInputStream(); File file = new File(path + name); FileOutputStream out = new FileOutputStream(file, true); int counter = 0; int ch; byte[] buffer = new byte[1024]; while ((ch = in.read(buffer)) != -1) { out.write(buffer, 0, ch); counter += ch; System.out.println(counter + ":byte"); } out.flush(); in.close(); out.close(); }}

Ⅵ Java文件下载怎么实现的

下载就很简单了把你要下载的文件做成超级链接,可以不用任何组件比如说下载一个word文档<a href="名称.doc">名称.doc</a>路径你自己写import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.RandomAccessFile;import java.net.HttpURLConnection;import java.net.ProtocolException;import java.net.URI;import java.net.URL;import java.util.Random;/** * * 实现了下载的功能*/ public class SimpleTh {public static void main(String[] args){ // TODO Auto-generated method stub //String path = "http://www.7cd.cn/QingTengPics/倩女幽魂.mp3";//MP3下载的地址 String path ="http://img.99luna.com/music/%CF%EB%C4%E3%BE%CD%D0%B4%D0%C5.mp3"; try { new SimpleTh().download(path, 3); //对象调用下载的方法 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static String getFilename(String path){//获得文件的名字 return path.substring(path.lastIndexOf('/')+1); }public void download(String path,int threadsize) throws Exception//下载的方法 {//参数 下载地址,线程数量 URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection)url.openConnection();//获取HttpURLConnection对象 conn.setRequestMethod("GET");//设置请求格式,这里是GET格式 conn.setReadTimeout(5*1000);// int filelength = conn.getContentLength();//获取要下载文件的长度 String filename = getFilename(path); File saveFile = new File(filename); RandomAccessFile accessFile = new RandomAccessFile(saveFile, "rwd"); accessFile.setLength(filelength); accessFile.close(); int block = filelength%threadsize ==0?filelength/threadsize:filelength/threadsize+1; for(int threadid = 0;threadid<=threadsize;threadid++){ new DownloadThread(url,saveFile,block,threadid).start(); } } private final class DownloadThread extends Thread{ private URL url; private File saveFile; private int block;//每条线程下载的长度 private int threadid;//线程id public DownloadThread(URL url,File saveFile,int block,int threadid){ this.url = url; this.saveFile= saveFile; this.block = block; this.threadid = threadid; } @Override public void run() { //计算开始位置的公式:线程id*每条线程下载的数据长度=? //计算结束位置的公式:(线程id+1)*每条线程下载数据长度-1=? int startposition = threadid*block; int endposition = (threadid+1)*block-1; try { try { RandomAccessFile accessFile = new RandomAccessFile(saveFile, "rwd"); accessFile.seek(startposition);//设置从什么位置写入数据 HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("GET"); conn.setReadTimeout(5*1000); conn.setRequestProperty("Range","bytes= "+startposition+"-"+endposition); InputStream inStream = conn.getInputStream(); byte[]buffer = new byte[1024]; int len = 0; while((len = inStream.read(buffer))!=-1){ accessFile.write(buffer, 0, len); } inStream.close(); accessFile.close(); System.out.println("线程id:"+threadid+"下载完成"); } catch (FileNotFoundException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } } }}

Ⅶ java怎样实现数据下载功能呢

这是我以前弄的一个下载的模块,里面的pl指的是System.out.println(),详情可以看 http://magbt.com/forum.php?mod=viewthread&tid=156package com.jc.download;import java.io.BufferedInputStream;import java.io.File;import java.io.IOException;import java.io.RandomAccessFile;import java.net.HttpURLConnection;import java.net.URL;import static com.jc.tool.io.Out.pl;public class DownloadThread extends Thread {private String url = null;private String file = null;private long offset = 0;private long length = 0;private int no = 0;public DownloadThread(String url, String file, long offset, long length) {pl("正在初始化下载线程…");this.url = url;this.file = file;this.offset = offset;this.length = length;}public void setNo(int no) {this.no = no;}@Overridepublic void run() {try {pl("线程【"+no+"】开始连接主机…");HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();pl("线程【"+no+"】发送下载请求…");conn.setRequestMethod("GET");conn.setRequestProperty("RANGE", "bytes=" + this.offset + "-"+ (this.offset + this.length – 1));pl("线程【"+no+"】创建文件流…");BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());byte[] buf = new byte[1024];int bytesRead;pl("线程【"+no+"】开始向文件写入数据…");while ((bytesRead = bis.read(buf, 0, buf.length)) != -1) {this.writeFile(file, offset, buf, bytesRead);this.offset += bytesRead;}pl("线程【"+no+"】写入完成");} catch (IOException e) {e.printStackTrace();}pl("线程【"+no+"】退出");}public void writeFile(String fileName, long offset, byte[] bytes,int realLength) throws IOException {File file = new File(fileName);RandomAccessFile raf = new RandomAccessFile(file, "rw");raf.seek(offset);raf.write(bytes, 0, realLength);raf.close();}}

Ⅷ 大数据中的java是什么

Java是由Sun Microsystems公司推出的Java面向对象程序设计语言(以下简称Java语言)和Java平台的总称。Java由James Gosling和同事们共同研发,并在1995年正式推出。Java最初被称为Oak,是1991年为消费类电子产品的嵌入式芯片而设计的。1995年更名为Java,并重新设计用于开发Internet应用程序用Java实现的HotJava浏览器(支持Java applet)显示了Java的魅力:跨平台、动态Web、Internet计算。从此,Java被广泛接受并推动了Web的迅速发展,常用的浏览器均支持Javaapplet。另一方面,Java技术也不断更新。Java自面世后就非常流行,发展迅速,对C++语言形成有力冲击。在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。2010年Oracle公司收购Sun Microsystems大数据技术是以数据为本质的新一代革命性的信息技术,在数据挖潜过程中,能够带动理念、模式、技术及应用实践的创新。本书系统性地介绍了大数据的概念、发展历程、市场价值、大数据相关技术,以及大数据对中国信息化建设、智慧城市、广告、媒体等领域的核心支撑作用,并对对数据科学理论做了初步探索。

Ⅸ java 大数据怎么做

Java是编程语言;大数据是一个概念,包含的技术较多,比如Hadoop、Spark、Storm等;学习大数据先要学习Java,Java是基础,而大数据比较核心的两个课程是HADOOP、SPARK。

赞(0)