日期:2014-05-20 浏览次数:20688 次
public class Ex19_10 { public static void main(String[] args) throws IOException{ // TODO 自动生成方法存根 if(args.length!=2){ System.out.println("Invalid param"); System.exit(0); } BufferedInputStream input = new BufferedInputStream( new FileInputStream(args[0])); int numberOfPieces = Integer.parseInt(args[1]); long splitFileSize = (int)(Math.ceil(1.0*input.available()/numberOfPieces)); System.out.println("FileSize: "+input.available()+" bytes"); for(int i = 1; i<= numberOfPieces; i++){ int count = 0; int value = 0; BufferedOutputStream output = new BufferedOutputStream( new FileOutputStream(i+".txt")); while((count++<splitFileSize)&&(( value = input.read())!=-1)) output.write(value); output.close(); } input.close(); } }