文件下载问题
package com.net;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
public class DownLoad
{
//private String URL="http://js.tudouui.com/bin/lingtong/PortalPlayer_55.swf";
private String URL="http://static.youku.com/v1.0.0364/v/swf/loader.swf";
private String fileSavePath="f:/";
//
public void down(String url,String filepath)
{
URL ur;
try {
//创建连接
ur = new URL(URL);
HttpURLConnection httpConnection=(HttpURLConnection)ur.openConnection();
// 获得输入流
InputStream input = httpConnection.getInputStream();
RandomAccessFile oSavedFile = new RandomAccessFile(filepath,"rw");
//从输入流中读取信息写入到文件中
byte []b=new byte[1024];
int nRead;
while((nRead=input.read(b,0,1024))>0)
{
oSavedFile.write(b,0,nRead);
}
//关闭连接
httpConnection.disconnect();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public DownLoad()
{
String filename=URL.substring(URL.lastIndexOf("/"));
down(URL, fileSavePath+filename);
}
public static void main(String[] args)
{
new DownLoad();
}
}
这个是自己写的下载文件代码,但是为什么下不下来?求大神指教 java download --------------------编程问答-------------------- String filename = URL.substring(URL.lastIndexOf("/")+1);
--------------------编程问答-------------------- String.substring(int)从指定索引处的字符开始 --------------------编程问答-------------------- 恩,索引还是不对,这个下载的文件没有下载完,
--------------------编程问答--------------------
http://static.youku.com/v1.0.0364/v/swf/loader.swf这个地址有问题
补充:Java , Java SE