IO、序列流、切割

//对多个文件进行合并! 要用到vector 
import
java.io.*; import java.util.*; public class Practice_2 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Vector<FileInputStream> v = new Vector<FileInputStream>(); v.add(new FileInputStream("1.txt")); v.add(new FileInputStream("2.txt")); v.add(new FileInputStream("3.txt")); Enumeration<FileInputStream> en = v.elements(); SequenceInputStream sis = new SequenceInputStream(en); FileOutputStream fos = new FileOutputStream("4.txt"); byte[] buf = new byte[1024]; int len = 0; while((len=sis.read(buf))!=-1) { fos.write(buf,0,len); } fos.close(); sis.close(); } }

切割:
public static void splitFile() throws IOException
    {
        FileInputStream fis = new FileInputStream("0828_1.jpg");
        FileOutputStream fos = null;
        
        byte[] buf = new byte[1024*1024];       //固定容器长度为 1M,数据存储了1M,自动存储到下一个文件当中。 
                            //如果想存个大一点的,100M为单位,那就订一个计数器,一次1M,存到100M,在输出到第二个的文档。
int len = 0; int count = 1; while((len=fis.read(buf))!=-1) { fos = new FileOutputStream("splitFiles"+(count++)+".part"); fos.write(buf,0,len); fos.close(); } fis.close(); }

 

 

 

posted @ 2019-10-14 16:22  蚂蚁雅黑1010  阅读(142)  评论(0编辑  收藏  举报