当前位置: 技术问答>java相关
请问那位有原断点续传的原码...(要支持上传和下载)???或者讲讲应该怎么实现...
来源: 互联网 发布时间:2015-07-17
本文导语: rt | 我给你一个我写的ftp下载的(分三个帖子),http我有,你来mail吧,我的mail:c33c@sohu.com file_info.java//得到url等 import java.net.*; import java.io.*; class File_info { String sDown_file; public Fil...
rt
|
我给你一个我写的ftp下载的(分三个帖子),http我有,你来mail吧,我的mail:c33c@sohu.com
file_info.java//得到url等
import java.net.*;
import java.io.*;
class File_info
{
String sDown_file;
public File_info(String s1)
{
sDown_file = s1;
}
public String get_url()
{
int nStart_number = sDown_file.indexOf("//");
if (nStart_number == -1)
{
return "-1" ;//-1表明此地址不是ftp地址,不含有"//"
}
else
{
int nSecond_number = sDown_file.indexOf("/",nStart_number+3);
if (nSecond_number == -1)
{
return "-1" ; //-1表明此地址不是ftp地址,不含有"/"
}
else
{
String url = sDown_file.substring(nStart_number + 2,nSecond_number);
return url;
}
}
}
public String get_down_file()
{
int nStr_length = sDown_file.length();
int nStart_number = sDown_file.indexOf("//");
if (nStart_number == -1)
{
return "-1" ;//-1表明此地址不是ftp地址,不含有"//"
}
else
{
int nSecond_number = sDown_file.indexOf("/",nStart_number+3);
if (nSecond_number == -1)
{
return "-1"; //-1表明此地址不是ftp地址,不含有"/"
}
else
{
String url = sDown_file.substring(nSecond_number + 1 , nStr_length);
return url;
}
}
}
public String get_IP()
{
String url = this.get_url();
try
{
String ip = InetAddress.getByName(url).toString();
return ip;
}
catch(UnknownHostException e)
{
return "-1"; //-1表示错误的主机
}
catch(IOException e2)
{
return "-2";//-2表示错误的输入输出流
}
}
}
FileAccess.java//写入文件
import java.io.*;
public class FileAccess implements Serializable
{
RandomAccessFile oSaveFile = null ;
long nPos;
public FileAccess(String sName,long npos) throws IOException
{
oSaveFile = new RandomAccessFile(sName,"rw");
this.nPos = npos;
oSaveFile.seek(nPos);
}
public synchronized int write(byte[] b, int nStart, int nLen)
{
try
{
int n = -1 ;
oSaveFile.write(b,nStart,nLen);
n = nLen;
return n;
}
catch(IOException e)
{
return -2;
}
}
file_info.java//得到url等
import java.net.*;
import java.io.*;
class File_info
{
String sDown_file;
public File_info(String s1)
{
sDown_file = s1;
}
public String get_url()
{
int nStart_number = sDown_file.indexOf("//");
if (nStart_number == -1)
{
return "-1" ;//-1表明此地址不是ftp地址,不含有"//"
}
else
{
int nSecond_number = sDown_file.indexOf("/",nStart_number+3);
if (nSecond_number == -1)
{
return "-1" ; //-1表明此地址不是ftp地址,不含有"/"
}
else
{
String url = sDown_file.substring(nStart_number + 2,nSecond_number);
return url;
}
}
}
public String get_down_file()
{
int nStr_length = sDown_file.length();
int nStart_number = sDown_file.indexOf("//");
if (nStart_number == -1)
{
return "-1" ;//-1表明此地址不是ftp地址,不含有"//"
}
else
{
int nSecond_number = sDown_file.indexOf("/",nStart_number+3);
if (nSecond_number == -1)
{
return "-1"; //-1表明此地址不是ftp地址,不含有"/"
}
else
{
String url = sDown_file.substring(nSecond_number + 1 , nStr_length);
return url;
}
}
}
public String get_IP()
{
String url = this.get_url();
try
{
String ip = InetAddress.getByName(url).toString();
return ip;
}
catch(UnknownHostException e)
{
return "-1"; //-1表示错误的主机
}
catch(IOException e2)
{
return "-2";//-2表示错误的输入输出流
}
}
}
FileAccess.java//写入文件
import java.io.*;
public class FileAccess implements Serializable
{
RandomAccessFile oSaveFile = null ;
long nPos;
public FileAccess(String sName,long npos) throws IOException
{
oSaveFile = new RandomAccessFile(sName,"rw");
this.nPos = npos;
oSaveFile.seek(nPos);
}
public synchronized int write(byte[] b, int nStart, int nLen)
{
try
{
int n = -1 ;
oSaveFile.write(b,nStart,nLen);
n = nLen;
return n;
}
catch(IOException e)
{
return -2;
}
}
|
IBM公司的DELELOPER网站上面有专门的介绍断点续传的例子,而且有例子说明,简单修改以下就可以调试通过,我试过的。