您的位置:首页 > 其它

文件的切割与合并(视频文件或者压缩文件)

2017-03-22 21:57 429 查看
public class Test {

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
try {
segmentation();   //文件的切割
aggregation();	 //文件的合并
} catch (IOException e) {

e.printStackTrace();
}

}

public static void segmentation() throws IOException{
//选中的文件地址是       D:\soft\screencapture.zip 大小为197MB
File file=new File("D:\\soft\\screencapture.zip");
InputStream in=new FileInputStream(file);
OutputStream out=null;
byte[] bytes=new byte[(int) (file.length()/5)+1];
System.out.println(file.length());
for (int i = 0; i < 5; i++) {
File file2 =new File("D:\\soft\\screencapture"+i+".zip");
out=new FileOutputStream(file2);
int len=in.read(bytes);
out.write(bytes,0,len);

}
out.close();
in.close();
}

public static void aggregation() throws IOException{
InputStream in=null;
OutputStream out=null;
for (int i = 0; i < 5; i++) {
File file =new File("D:\\soft\\screencapture"+i+".zip");
in =new FileInputStream(file);
out=new FileOutputStream("D:\\soft\\新.zip",true);
int len =-1;
byte[] b =new byte[10240];
while ((len=in.read(b))!=-1) {
out.write(b, 0, len);
}
}
out.close();
in.close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: