Java 实现文件分割合并的代码
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
相关文档:
当一个复杂的对象被构造时,它的构造函数按下面的顺序被调用(that the order of constructor calls for a complex object is as follows)
1.其基类(base-class)的构造函数被调用,这个步骤以递归的方式重复,所以最底层(the root of hierarchy)的构造函数首先被执行,然后是它上一层派生类(the next-deriv ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
计算机专业毕业两年了,终于找到学习的感觉了,后悔当时在学校时的无知和狂妄!!!
现在我对Java web编程有了兴趣,我写了自己的用户登录小程序,已经上传到我的CSDN空间了,欢迎大家来访问!!!
讨论之后,欢迎来信,共同提高!!!
联系方式:243093502@@qq.com ......