文件分割程序

import java.io.*;
class mycut
{
public static void main(String args[]) throws Exception
{
int num;
String fn;//文件名
String fss;//分割份数]
int fs;//分割份数
FileInputStream fin;
FileOutputStream fbat;
FileOutputStream fout;
String name;
File f;
byte[] fb=new byte[1024];
int fsum=0;//用于核对文件大小
System.out.println("欢迎使用nicend文件分割器——http://nicend.bokee.com");
System.out.print("请输入要分割的文件名:");
num=System.in.read(fb);
fn=new String(fb,0,num-2);
f=new File(fn);
System.out.println("文件大小:"+f.length()+" b");
System.out.print("请输入分割文件份数:");
num=System.in.read(fb);
fss=new String(fb,0,num-2);
fs=Integer.parseInt(fss);
if(fs<2)
{System.out.print("份数最少为2");System.exit(0);}
System.out.print("开始分割.../n");
name=new String(fn.getBytes(),0,fn.lastIndexOf("."));
File fdir=new File(".//"+name+"分割文件");
fdir.mkdirs();
fin=new FileInputStream(fn);//原文件
fbat=new FileOutputStream(fdir.toString()+" //"+name+"合并"+".bat");
fbat.write(new String("copy /b "+name+"0.nicend"+"+"+name+"1.nicend "+fn).getBytes());
byte[] ch=new byte[new Long(f.length()/fs+1).intValue()];
int i=0;
int sum=0;
num=fin.read(ch);
while(num!=-1)
{
fout=new FileOutputStream(fdir.toString()+" //"+name+i+".nicend");
if(i>1)
fbat.write(new String("/r/ncopy /b "+fn+"+"+name+i+".nicend").getBytes());//这里要用/b是以二进制运行
fout.write(ch,0,num);
fsum+=num;
System.out.println(num);
fout.close();
i++;
num=fin.read(ch);
}//while
System.out.println("        :="+fsum);
fin.close();
fbat.close();
if(f.length()==fsum)//判断分割是否成功,即文件大小是否一样
System.out.print("分割完成!");
else
System.out.print("分割出错,文件大小不一至!");
}//main
}//class
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值