时间:2021-07-01 10:21:17 帮助过:5人阅读
RandomAccessFile raf=new RandomAccessFile(文件对象,读写模式);r只读,rw读和写
private File f;
//目的地
private String dir;
//所有分割后的文件存储路径
private List<String> list;
//每块大小
private int blockSize;
//块数
private int size;
public n(File f,String dir,int blockSize)
{
this.f=f;
this.dir=dir;
this.blockSize=blockSize;
this.list=new ArrayList<String>;
}
//初始化
private void init()
{
//总长度
long len=this.f.length();
//块数
this.size=(int)Math.ceil(len*1.0/blockSize);
//路径:
for(int i=0;i<size;i++)
{
this.list.add(this.dir+i+this.f.getName());
}
}
//分割:计算每一块的起始位置及大小
public void split()
{
}
public void t3(int i,int first,int real) throws IOException
{
RandomAccessFile raf=new RandomAccessFile(this.f,"r");
RandomAccessFile raf2=new RandomAccessFile(this.list.get(i),"rw");
raf.seek(first);//从第二个位置开始
byte[] flush=new byte[1024];
int len=-1;
while((len=raf.read(flush))!=-1)
{
if(real>1024)
{
raf2.write(flush,0,len);
real-=1024;
}else
{
raf2.write(flush,0,real);
break; //读取指定大小,读完退出
}
raf2.close();
raf.close();
}
}
public static void main(String[]args)
{
}
}
java _io_随机读取读入流RandomAccessFile
标签:split static 支持 except 读写 arraylist mat list and