码迷,mamicode.com
首页 > 其他好文 > 详细

IO流(序列流)

时间:2018-06-18 23:19:11      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:string   row   while   output   inpu   except   static   seq   tst   

package com.day17.IO;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.SequenceInputStream;

public class OtherIO {

    public static void main(String[] args) throws IOException {
        fun();
        
        FileInputStream fis1=new FileInputStream("a.txt");
        FileInputStream fis2=new FileInputStream("b.txt");
        SequenceInputStream sis=new SequenceInputStream(fis1,fis2);
        FileOutputStream fos=new FileOutputStream("c.txt");
        int b;
        while((b=sis.read())!=-1) {
            fos.write(b);
        }
        sis.close();
        fos.close();
    }

    private static void fun() throws FileNotFoundException, IOException {
        FileInputStream fis1=new FileInputStream("a.txt");
        //FileInputStream fis2=new FileInputStream("b.txt");
        FileOutputStream fos=new FileOutputStream("c.txt");
        int b1;
        while((b1=fis1.read())!=-1) {
            fos.write(b1);
        }
        fis1.close();
        
        FileInputStream fis2=new FileInputStream("b.txt");
        int b2;
        while((b2=fis2.read())!=-1) {
            fos.write(b2);
        }
        fis2.close();
        fos.close();
    }

}

 

IO流(序列流)

标签:string   row   while   output   inpu   except   static   seq   tst   

原文地址:https://www.cnblogs.com/zhujialei123/p/9196585.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!