编写程序,将一个视频文件,切割成指定大小的文件块 将上面切割出来的文件,合并成一个文件。
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {
System.out.println("请输入想要切割数量");
Scanner scan=new Scanner(System.in);
int num=scan.nextInt();
scan.close();
qie(num); //文件的切割
System.out.println("切割成功,请在F盘中查看!");
he(num);
System.out.println("重新合成成功,请在F盘中查看!");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void qie(int num) throws IOException{
File file1=new File("F:\\shipin.wmv");
InputStream ins=new FileInputStream(file1);
OutputStream outs=null;
byte[] b=new byte[(int) (file1.length()/num)+1];
for (int i = 0; i < num; i++)
{
File file2 =new File("F:\\shipin"+i+".wmv");
outs=new FileOutputStream(file2);
int len=ins.read(b);
outs.write(b,0,len); //将指定 b数组中从偏移量0开始的 len 个字节写入此输出流
}
outs.close();
ins.close();
}
public static void he(int num) throws IOException{
InputStream ins=null;
OutputStream outs=null;
for (int i = 0; i < num; i++)
{
File file =new File("F:\\shipin"+i+".wmv");
ins =new FileInputStream(file);
outs=new FileOutputStream("F:\\新.wmv",true);
int len =-1;
byte[] b =new byte[1024];
while ((len=ins.read(b))!=-1) {
outs.write(b, 0, len);
}
}
outs.close();
ins.close();
}