首页(162) xml(5) spring(1) 生活(8) java(70) 代码(10) 英语(4) 数据库(7) c#(14) 成长(10) 软件工程(27)  写新日志
 
 

玻璃杯中的花生壳

  真爱的事业和真正的爱情一生只有一次,都值得我们温柔地相待,因为那种感觉是永远都无法复制的, 这世界真正属于你的东西其实并不多,你不好好珍惜,它便会离你而去,包括机遇,包括爱情,包括生命。
   不要找任何理由,  当幸福在你身边的时候就抓住它,你就一定会很幸福! 
   

时 间 记 忆
«September 2025»
123456
78910111213
14151617181920
21222324252627
282930

最 新 评 论
回复:xml的Jdom解析过程详解
回复:突然想到的几句话!
 Boyle came out of n
回复:xml的Jdom解析过程详解
回复:配置Spring数据源
回复:使用SAX解析XML
回复:java中写文件操作时FileOu
回复:关联和依赖关系的区分
回复:HttpSessionListen
回复:Spring AOP四种创建通知(

最 新 日 志
Java开发者的十大戒律
配置Spring数据源
java多线程设计模式
java中switch的使用
性格,编码,测试
突然想到的几句话!
理解Spring AOP中的关键概念
Spring AOP四种创建通知(拦截器
xml的四种解析方法 比较 sax,do
xml的Jdom解析过程详解

最 新 留 言
签写新留言

我渴望知识
很好的东东
帖子不错,道声谢
想拜师学艺
我的呼喊

搜 索


用 户 登 录
用户名称:
登陆密码:
密码保存:

友 情 连 接

模板设计:部落窝模板世界

blog名称:玻璃杯中的花生壳
日志总数:162
评论数量:249
留言数量:1
访问次数:826986
建立时间:2004年11月4日
 
 
 
[代码]用Java简单实现文件分割与合并
[ 2006/8/22 16:25:47 | By: 玻璃杯中的花生壳 ]
 
主要应用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<value;j++){    File outFile = new File(inFile.getName()+j+"zzii");    RandomAccessFile outt= new RandomAccessFile(outFile,"rw");    maxx+=size;    for (;i<maxx;i++){     outt.write(inn.read());    }    outt.close();   }   File outFile = new File(inFile.getName()+j+"zzii");   RandomAccessFile outt= new RandomAccessFile(outFile,"rw");   for(;i<fileLength;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& bsp;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<tt.length;i++){     System.out.println(tt[i]);    }        //打开所有的文件再写入到一个文件里    for(int i=0;i<tt.length;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(我设置的方便标识)");}}
 

阅读全文(2238) | 回复(0) | 编辑 | 精华
 

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)
 
部落窝Blog模板世界部落窝Blog模板世界
站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.031 second(s), page refreshed 144774645 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号