用Java简单实现文件分割与合并 (1)
主要应用IO的RandomAccessFile(听说断点续传也是用它实现) k??乌????
import java.io.*; \ ??qX驹?
??? -芦?
class Fen{ ??u??}????
String fileName; ??@??C*^
int size; cT"{点K?
|t???? F?
Fen(String fileName,String size){ ??? ?8M
this.fileName = fileName; 顿??$A<??
this.size = Integer.parseInt(size)*1024; 菇?%??帷L
} Ox??P???
h??????
public void cut()throws Exception{ 躁??X???0
int maxx = 0; ?????}v?
File inFile = new File(fileName); ?E???????
??H???
int fileLength = (int)inFile.length(); //取得文件的大小 ??ms??????
int value; //取得要分割的个数 H_s????n
??2放e|N
RandomAccessFile inn = new RandomAccessFile(inFile,"r");//打开要分割的文件 ????I????
??????H???
?.pd愀aNv
value = fileLength/size; a??姝$vi
>悼S???O0
int i=0; 9t??F??铉
int j=0; ???H????
晋>???p?
//根据要分割的数目输出文件 昃??X??[
for (;j File outFile = new File(inFile.getName()+j+"zzii"); ????)p???
RandomAccessFile outt= new RandomAccessFile(outFile,"rw"); N?2wK沈?
maxx+=size; 豸 ???6??
for (;i outt.write(inn.read()); 3?G??k|1? 


您的位置:
