国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用Java簡單實現文件分割與合并

2019-11-18 11:33:09
字體:
來源:轉載
供稿:網友

  主要應用IO的RandomaccessFile(聽說斷點續傳也是用它實現)
 import java.io.*;

class Fen{
String fileName;
int size;

Fen(String fileName,String size){
this.fileName = fileName;
this.size = Integer.parseInt(size)*1024;
}

public void cut()throws Exception{
int maxx = 0;
File inFile = new File(fileName);

int fileLength = (int)inFile.length(); //取得文件的大小
int value; //取得要分割的個數

RandomAccessFile inn = new RandomAccessFile(inFile,"r");//打開要分割的文件


value = fileLength/size;

int i=0;
int j=0;

//根據要分割的數目輸出文件
for (;j File outFile = new File(inFile.getName()+j+"zzii");
RandomAccessFile outt= new RandomAccessFile(outFile,"rw");
maxx+=size;
for (;i outt.write(inn.read());
}
outt.close();
}
File outFile = new File(inFile.getName()+j+"zzii");
RandomAccessFile outt= new RandomAccessFile(outFile,"rw");
for(;i
outt.write(inn.read());
}
outt.close();

inn.close();
}
}


class He{
String fileName;
String filterName;

He(String fileName,String filterName){
this.fileName = fileName;
this.filterName = filterName;
}


public void unite()throws Exception{
String [] tt;
File inFile = new File("."); //在當前目錄下的文件
File outFile = new File(fileName); //取得輸出名
RandomAccessFile outt= new RandomAccessFile(outFile,"rw");

//取得符合條件的文件名
tt = inFile.list(new FilenameFilter(){
public boolean accept(File dir,String name){
String rr = new File(name).toString();
return rr.endsWith(filterName);
}
});
//打印出取得的文件名
for (int i = 0;i System.out.PRintln(tt[i]);
}

//打開所有的文件再寫入到一個文件里
for(int i=0;i inFile = new File(tt[i]);
RandomAccessFile inn= new RandomAccessFile(inFile,"r");
int c;
while((c=inn.read())!=-1)
outt.write(c);
}

outt.close();
}
}


public class test{
public static void main(final String [] args)throws Exception{

if(args.length==0){
print();
return;
}
if(args[0].equals("-c")){
Fen cutt = new Fen(args[1],args[2]);
cutt.cut();
}
else if (args[0].equals("-r")){
He hee = new He(args[1],args[2]);
hee.unite();
}
else
print();

}

public static void print(){
System.out.println("usage:/n分: java test -c file1 size(單位為K)/n合 java test -r file2 zzii(我設置的方便標識)");
}
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丽水市| 雅安市| 卓资县| 江城| 福贡县| 镇远县| 雷山县| 赤水市| 邵阳县| 望江县| 延吉市| 营山县| 汉川市| 平罗县| 航空| 睢宁县| 英山县| 错那县| 永胜县| 华亭县| 佳木斯市| 武冈市| 新密市| 新泰市| 泗水县| 武强县| 丰镇市| 长武县| 石城县| 日土县| 通州市| 建昌县| 绥阳县| 奈曼旗| 成都市| 勃利县| 上林县| 图木舒克市| 怀宁县| 福海县| 卫辉市|