java下载网络数据
来源:互联网 发布:新卷皮 淘宝客 源码 编辑:程序博客网 时间:2024/04/26 06:22
package com.network;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/*
* 下载网络上的数据(图片,文件,视频)
*/
public class DownloadFile
{
public static void download(String urlpath,String filename,String savepath)
{
try {
URL url = new URL(urlpath);
URLConnection conn= url.openConnection();
conn.setConnectTimeout(5000);
InputStream in = conn.getInputStream();
File path = new File(savepath);
if(!path.exists())
{
path.mkdirs();
}
OutputStream out = new FileOutputStream(path.getPath()+"\\"+filename);
int len =0;
byte[] b = new byte[2048];
while((len=in.read(b))!=-1)
{
out.write(b, 0, len);
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
String path ="http://www.verydemo.com/demo_c98_i4648.html";
String filename="myfile.html";
String savepath = "d:/image";
download(path,filename,savepath);
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/*
* 下载网络上的数据(图片,文件,视频)
*/
public class DownloadFile
{
public static void download(String urlpath,String filename,String savepath)
{
try {
URL url = new URL(urlpath);
URLConnection conn= url.openConnection();
conn.setConnectTimeout(5000);
InputStream in = conn.getInputStream();
File path = new File(savepath);
if(!path.exists())
{
path.mkdirs();
}
OutputStream out = new FileOutputStream(path.getPath()+"\\"+filename);
int len =0;
byte[] b = new byte[2048];
while((len=in.read(b))!=-1)
{
out.write(b, 0, len);
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
String path ="http://www.verydemo.com/demo_c98_i4648.html";
String filename="myfile.html";
String savepath = "d:/image";
download(path,filename,savepath);
}
}
- java下载网络数据
- 网络数据下载优化:
- python3-网络数据下载
- Java 网络文件下载
- java 网络文件下载
- Java 下载网络图片
- java 断点续传网络下载
- Java下载网络图片
- java下载网络文件
- Java 下载网络图片
- Java 网络下载
- ListView分页+网络下载数据
- 使用ASI下载网络数据
- OC下载网络数据简介
- Java股票数据下载
- JAVA开发网络资料下载
- java网络下载小程序
- java 批量下载网络文件
- Blocks基础 Using Blocks in iOS 4: The Basics
- 那些年干过的事(六)—无源码修改版本号
- 算法入门3:分支算法(下)
- mysqlbinlog 查看mysql bin 日志
- 第十一周项目2-求最大公约数
- java下载网络数据
- Error when attempting to IMPORT object "MC11VAOHDR_TAB"
- Android Studio 0.3.2
- Android KEYCODE键值对应大全
- Mysql Binlog三种格式介绍及分析
- 任意输入两个年份并将这之间的闰年排列出来
- 那些年干过的事(序)
- bitnami-redmine-2.x 安装插件
- 黑马程序员--银行业务调度