有关断点续传后文件夹损坏的问题

具体下载的代码:

long endPos = bean.getEndLen();
long startPos = bean.getStartLen();
System.out.println(current.getId()
+ "-------------------当前线程ID--------当前线程临时文件" + itemFile.getClass().getName()
+ "-----文件的开始和结束位置----" + startPos + "---" + endPos);
while (endPos > startPos && !isDownloadOver) {
try {
URL url = new URL(bean.getFileUrl());
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
conn.setConnectTimeout(10000);
conn.setReadTimeout(10000);
InputStream is = new BufferedInputStream(conn
.getInputStream());

                byte[] buff = new byte[BUFF_LENGTH];
                int length = -1;

                while((length = is.read(buff)) > 0
                && startPos < endPos && !isDownloadOver) {
                    startPos += itemFile.write(buff, 0, length);
                    // 写入文件下载量
                    writePoint(bean, startPos + "");
                }
                is.close();
                conn.disconnect();
                System.out.println("分线程号:"+current.getId()+"下载完成");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

//写文件的类
public class FileAccess implements Serializable {
private RandomAccessFile oSavedFile;
@SuppressWarnings("unused")
private long nPos;

public FileAccess() throws IOException {
    this("");
}

public FileAccess(String sName) throws IOException {
    this.oSavedFile = new RandomAccessFile(sName, "rw");
    this.nPos = oSavedFile.length();
    this.oSavedFile.seek(nPos);
}

/**
 * 分写内容
 * @param b
 * @param nStart
 * @param nLen
 * @return
 */
public  int write(byte[] b, int nStart, int nLen) {
    int n = -1;
    try {
        this.oSavedFile.write(b,nStart,nLen);
        n = nLen;
    } catch(IOException e) {
        e.printStackTrace();
    }
    return n;
}


public  long  getSize() throws IOException{
    return oSavedFile.length();
}

public  void  close() throws IOException{
    oSavedFile.close();
    oSavedFile = null;
}

}

问题:如果不断,直接一次性下载文件就可以打开,但是如果断点后,在连的化,文件就无法打开了

从你给的代码看不出什么来,建议把完整代码打包发上来,好让大家调试。

一般损坏可能是范围问题:
如线程1写:
0----1000
线程2写:
1001----2000 (这个地如果从1000开始就会出问题)

此处是一个断点续传的例子
[url]http://www.oschina.net/code/list_releted_codes?id=624[/url]

关键点:
1、通过Http头: RANGE 2000070 来指定下载的byte范围
2、服务器从RANGE开始读文件