日期:2014-05-20  浏览次数:20707 次

从网上找了个文件分割器的例子,但是自己照着写就出问题,求大神给看一眼
package network;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.util.*;

public class Network {
    public static void main (String argv[]){
      Separatefile test=new Separatefile();
      test.Start("e:/test/1.pdf");
      
      
}
}

class Separatefile {
    String Filename=null;
    long Filesize=0;
    long BlockNumb=0;
    long Blocksize=100*1024;
    
   
    
    private void getInfo (String filepath)
    {
        File origin=new File(filepath);
        Filename=origin.getName();
        Filesize=origin.length();
        if(Filesize%Blocksize>0)
        {
            BlockNumb=Filesize/Blocksize+1;
        } else
        {
            BlockNumb=Filesize/Blocksize;
        }
        //System.out.println(Filename+","+Filesize+","+BlockNumb);
    }
    private String generateName (int filecounter)
    {
        
        return Filename+".part"+filecounter;
    }
    private boolean writeFile(String filepath, String fileIndividualName,long blocksize, long beginPos)
    {
        RandomAccessFile raf=null;
        FileOutputStream fos=null;
        byte[] bt=new byte[1024];
        long writebyte=0;
        int len=0;
        
        try
        {
            raf=new RandomAccessFile(filepath,"r");
            raf.seek(beginPos);
            fos=new FileOutputStream(fileIndividualName);
            while((len=raf.read(bt))>0)
            {
                if(writebyte<blocksize)
                {
                    writebyte=writebyte+len;
                
                 if(writebyte<=blocksize)
                    fos.write(bt,0,len);
                 else
                  {
                    len=len-(int)(writebyte-blocksize);
                    fos.write(bt, 0, len);
                  }
                }
            }
        
            fos.close();
            raf.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        
        try
        {
            if(fos!=null)
                fos.close();