通过HTTP形式从服务器下载文件要怎么弄啊? 客户端程序需要从服务器下载文件,通过HTTP的,不是JSP,请问要怎么实现啊?最好提供一下代码,谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你需要下载的,不属于标准JDKhttp://blog.alsox.com/article_189/这篇文章可能对你有用 BufferedInputStream br = null;HttpURLConnection connection = null; URL url = new URL(path);connection = (HttpURLConnection) url.openConnection();br = new BufferedInputStream(connection.getInputStream());byte[] buffer = new byte[connection.getContentLength()+1];br.read(buffer); if (br != null) { br.close(); br = null; } if (connection != null) { connection.disconnect(); connection = null; } import java.net.*;import java.io.*;public class ReadURL3 { public static void main(String argv[]) throws Exception { URL url = new URL("http://localhost:8080/images/logo.gif");// URL url = new URL("http://localhost:8080/css/default.css"); BufferedInputStream in = new BufferedInputStream(url.openStream()); BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream("f:\\temp\\mylogo.gif")); int r; while ((r = in.read()) != -1) { out.write(r); } in.close(); out.close(); }} 有高人能还原算法吗。。。。 一个简单的JAVA实验 ,不知道怎么老有问题,求解! 谈谈自己的失败的项目或者工作中学习中遇到最困难的问题 请教一个保存数据的问!(简单) 谁有这几个包. Can recommend a better java compression library? 一个文件读写的问题 要求抛出异常,应该如何写? java中用什么方法调用外部可执行文件? 这个什么意思 怪事了,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 菜鸟问题!字符和字符串相加。
http://blog.alsox.com/article_189/
这篇文章可能对你有用
HttpURLConnection connection = null;
URL url = new URL(path);
connection = (HttpURLConnection) url.openConnection();
br = new BufferedInputStream(connection.getInputStream());
byte[] buffer = new byte[connection.getContentLength()+1];
br.read(buffer);
if (br != null) {
br.close();
br = null;
}
if (connection != null) {
connection.disconnect();
connection = null;
}
import java.io.*;public class ReadURL3 {
public static void main(String argv[]) throws Exception {
URL url = new URL("http://localhost:8080/images/logo.gif");
// URL url = new URL("http://localhost:8080/css/default.css"); BufferedInputStream in
= new BufferedInputStream(url.openStream());
BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream("f:\\temp\\mylogo.gif")); int r;
while ((r = in.read()) != -1) {
out.write(r);
}
in.close();
out.close(); }
}