java基础—文件的切割与合并
来源:互联网 发布:acm规则知乎 编辑:程序博客网 时间:2024/05/11 09:18
文件的切割与合并
import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.SequenceInputStream;import java.util.ArrayList;import java.util.Enumeration;import java.util.Vector;public class FileSplieDemos {public static void main(String[] args) throws Exception {File theReadPath = new File("C:\\Users\\Administrator\\Desktop\\测试文件夹\\凤舞九天.mp3");String theOutPath ="C:\\Users\\Administrator\\Desktop\\测试文件夹\\abc\\";// 调用自定义方法将一个图片文件进行切割SplieFile(theReadPath,theOutPath,new File(".mp3"));//调用自定义方法将这些被分割的文件合并起String theMergerpathout = "C:\\Users\\Administrator\\Desktop\\测试文件夹\\abCOPY\\";String themergerInputpath="C:\\Users\\Administrator\\Desktop\\测试文件夹\\abc\\";String theoutformat = "MergerCopy.mp3";MergerFile(themergerInputpath,theMergerpathout,theoutformat);}private static void MergerFile(String themergerInputpath,String theMergerpathout, String theoutformat) throws Exception {// TODO Auto-generated method stubFile fil = new File(theMergerpathout);if(!(fil.isDirectory())){fil.mkdirs();}//将文件来源封装对象File file = new File(themergerInputpath);//获取所有块片的文件File[] names = file.listFiles();//创建一个容器,将所有的文件名字储存Vector<FileInputStream> v = new Vector<FileInputStream>();for(int x=0;x<names.length;x++){v.add(new FileInputStream(names[x]));}Enumeration<FileInputStream> en = v.elements();//合并多个流对象SequenceInputStream sis = new SequenceInputStream(en);//创建输出流对象BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(theMergerpathout+theoutformat));int len = 0;byte[] b = new byte[1024*1024];while((len=sis.read(b))!=-1){bos.write(b);bos.flush();}}private static void SplieFile(File file,String thepath,File format){// 通过字节流并联需要切割的文件对象,并加入缓冲技术提高效率System.out.println("切割文件功能启动");File fil = new File(thepath);if(!(fil.isDirectory())){fil.mkdirs();}BufferedInputStream bis = null;BufferedOutputStream bos = null;int number = 0;try {bis = new BufferedInputStream(new FileInputStream(file));//初使化输出路径byte[] b = new byte[1024*1024]; int len = 0; while((len = bis.read(b))!=-1) { number++; bos = new BufferedOutputStream(new FileOutputStream(thepath+number+format)); bos.write(b); bos.flush(); }} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
1 0
- java基础—文件的切割与合并
- java基础—文件的切割与合并
- Java基础----文件的切割合并
- java 文件切割与合并
- java文件切割与合并
- 文件的切割与合并
- 文件的切割与合并
- 【java基础:IO】带配置文件的文件切割与合并Demostration
- java基础学习笔记——I/O文件切割与合并
- Java---文件的切割与合并,已经实现图形界面(工具)
- Java---练习:文件切割与合并(1)
- Java IO流文件切割 与合并
- 文件切割与合并
- 文件切割与合并
- java切割合并文件
- 黑马程序员——文件的切割,与合并
- 黑马程序员——文件的切割与合并
- 黑马程序员—文件的切割与合并
- JavaScript 2048小游戏
- PathEffect介绍
- 试一下LaTeX
- HelloWorld
- 判断回文,位与,位或
- java基础—文件的切割与合并
- Billboard(线段树区间更新与求值)
- CSS3感应鼠标背景闪烁和图片缩放效果
- 4th Median of Two Sorted Arrays -- leetcode
- C++程序设计--对象分册(第5章)
- 黑马day06 EL表达式之cout&cset&cremove标签
- 搭建andriod开发环境
- 微信公众平台开发:JS API支付
- 保护眼睛的桌面设置