国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
用Java簡單實現(xiàn)文件分割與合并
主要應用IO的RandomAccessFile(聽說斷點續(xù)傳也是用它實現(xiàn)) 
 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;             //取得要分割的個數(shù)
   
   RandomAccessFile inn = new RandomAccessFile(inFile,"r");//打開要分割的文件
   
   
   value = fileLength/size;
   
   int i=0;
   int j=0;
   
   //根據要分割的數(shù)目輸出文件
   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 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(我設置的方便標識)");
}
}

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C++讀取寫入.txt文件(ifstream/ofstream)
R腳本執(zhí)行
最大子序列和問題
java實現(xiàn)文件拷貝
自制 Python小工具 將markdown文件轉換成Html文件
130+ 條 Vim 常用命令
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服