package cn.stat.p1.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Properties; public class qiefiledemo { private static int SIZE=1024*1024;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException { //文件切割
File file=new File("D:\\3.avi");
splitFile(file); //文件组合
File file2=new File("D:\\cc");
mergeFile(file2); }
//文件组合
public static void mergeFile(File dir) throws IOException
{
//读取配置文件
File[] files =dir.listFiles(new sufFilter(".properties")); //判断文件是否存在
if(files.length!=1)
throw new RuntimeException("文件不存在"); //创建文件流
File fl=files[0];
//获取文件信息
Properties prot=new Properties();
FileInputStream fis=new FileInputStream(fl);
prot.load(fis); String filename=prot.getProperty("filename");
int count=Integer.parseInt(prot.getProperty("patconut")); //获取目录下所有的碎片文件
File[] patfile=dir.listFiles(new sufFilter(".pat")); if(patfile.length!=count)
{
throw new RuntimeException("数目不对");
} ArrayList<FileInputStream> al=new ArrayList<FileInputStream>();
for(int i=0;i<patfile.length;i++)
{
al.add(new FileInputStream(new File(dir,i+".pat")));
} Enumeration<FileInputStream> en=Collections.enumeration(al);
SequenceInputStream sis=new SequenceInputStream(en);
FileOutputStream fos=new FileOutputStream(new File(dir,filename));
byte[] buf=new byte[SIZE];
int len=0;
while((len=sis.read(buf))!=-1)
{
fos.write(buf,0,len);
}
fos.close();
sis.close(); } //文件切割
public static void splitFile(File file) throws IOException
{
//用于读取流的关联文件
FileInputStream fis=new FileInputStream(file);
//定义一个1M的缓冲区
byte[] buf=new byte[SIZE]; //创建目地
FileOutputStream fos=null; //创建文件切割配置文件信息
Properties prop=new Properties(); int conut=0;
int len=0; File dir=new File("D:\\cc");
if(!dir.exists())
{
dir.mkdir();
} while((len=fis.read(buf))!=-1)
{
fos=new FileOutputStream(new File(dir,(conut++)+".pat"));
fos.write(buf,0,len);
} //创建配置文件
fos=new FileOutputStream(new File(dir,conut+".properties"));
prop.setProperty("patconut",conut+"");
prop.setProperty("filename",file.getName());
prop.store(fos,""); fos.close();
fis.close(); } }
package cn.stat.p1.file;

import java.io.File;
import java.io.FilenameFilter; public class sufFilter implements FilenameFilter { private String suffix; @Override
public boolean accept(File dir, String name) {
// TODO Auto-generated method stub
return name.endsWith(suffix);
} public sufFilter(String suffix) {
super();
this.suffix = suffix;
} }

java下io文件切割合并功能加配置文件的更多相关文章

  1. java下io文件切割合并功能

    package cn.stat.p1.file; import java.io.File; import java.io.FileInputStream; import java.io.FileNot ...

  2. Ajax+Java实现大文件切割上传

    技术体系:html5(formdata) + java + servlet3.0+maven + tomcat7 <!DOCTYPE html> <html> <head ...

  3. Ubuntu根目录下各文件夹的功能详细介绍

    Ubuntu的根目录下存在着很多的文件夹,但你知道他们都存放着哪些文件呢?这些是深入了解Ubuntu系统必不缺少的知识,本文就关于此做一下介绍吧. /bin/    用以存储二进制可执行命令文件. / ...

  4. Java基础IO文件拷贝练习题

    /** * 编写一个程序,把指定目录下的所有的带.java文件都拷贝到另一个目录中,拷贝成功后,把后缀名是.java的改成.txt. */ 1.我们看到这个题还是用大化小的思想来做 分析:1.拷贝 & ...

  5. jni 文件切割合并

    最近学习c++,看到很多常用的例子,比如文件切割,切割后后缀可以自定义,别人就无法从表面的一个文件看出是什么,也无法查看到原文件信息,只有合并后才能识别这庐山真面目 实现也比较粗暴,首先在应用层定义好 ...

  6. IO流--切割 合并文件

    import java.io.*; import java.util.*; public class io { public static void main(String[] args)throws ...

  7. Linux下的文件切割和文件合并

    linux下文件分割可以通过split命令来实现,可以指定按行数分割和按大小分割两种模式.Linux下文件合并可以通过cat命令来实现. 在Linux下用split进行文件分割: ①:指定分割后文件行 ...

  8. JAVA之IO文件读写

    IO概述:                                                          IO(Input output)流 作用:IO流用来处理设备之间的数据传输 ...

  9. Java多线程遍历文件夹,广度遍历加多线程加深度遍历结合

    复习IO操作,突然想写一个小工具,统计一下电脑里面的Java代码量还有注释率,最开始随手写了一个递归算法,遍历文件夹,比较简单,而且代码层次清晰,相对易于理解,代码如下:(完整代码贴在最后面,前面是功 ...

随机推荐

  1. div边框阴影的实现【转载】

    box-shadow:阴影水平偏移值(可取正负值): 阴影垂直偏移值(可取正负值):阴影模糊值:阴影颜色: Firefox支持Box Shadow(阴影):-moz-box-shadow:2px 2p ...

  2. 转载:Linux的vim三种模式

    一般模式:在Linux终端中输入“vim 文件名”就进入了一般模式,但不能输入文字. 编辑模式:在一般模式下按i就会进入编辑模式,此时就可以写程式,按Esc可回到一般模式. 命令模式:在一般模式下按: ...

  3. Python自动化运维之7、生成器、迭代器、列表解析、迭代器表达式

    迭代器和生成器 1.迭代器 迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退,不过这也没什么,因为人们很少在迭代途中往后退.另外 ...

  4. debug 输出 以及宏定义--备

    使用NSLog的一个风险是:它的运行会占用时间和设备资源. 所以在编译版本前一定不要有nslog. 同时当你的工程中有很多log 输出的时候 查找起来很不方便 ,下面介绍一种方法 可以使我们事半功倍. ...

  5. 转:CString::GetLength()获得字节数的正确方法

    前段时间,做http协议上传文件及断点续传控件时,在客户端采用C++调用CHttpConnection.CHttpFile进行文件上传.移植到Unicode编码时,上传得到的文件总是小于正常文件.最终 ...

  6. javascript scroll事件

    http://developer.51cto.com/art/201107/277994.htm onscroll事件 window.onscroll|| document.onscroll var ...

  7. js 中比较 undefined

    // x has not been declared before if (typeof x === 'undefined') { // evaluates to true without error ...

  8. 各种计算机语言的经典书籍(C/C++/Java/C#/VC/VB等)

    1.Java Java编程语言(第三版)-Java四大名著--James Gosling(Java之父) Java编程思想(第2版)--Java四大名著--Bruce Eckel Java编程思想(第 ...

  9. 带’*’号字符串的匹配

    目标: 判断源字符串中是否含有指定子串,子串可能会有*号通配符. 初步测试没问题.记录下来.后面要是有问题再来纠正. #include <string> using namespace s ...

  10. Codeforces Round #203 - D. Looking for Owls

    D. Looking for Owls Emperor Palpatine loves owls very much. The emperor has some blueprints with the ...