IO输入输出与反射机制1

package com.io1;

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

//复制
public class LianXi4 {

    public static void main(String[] args) {
        
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("e:/java/lianxi.txt");
            fos = new FileOutputStream("e:/java/test.txt");
            //
            int fiss =-1;
            String str = "";
            while((fiss = fis.read())!=-1) {
                str +=(char)fiss;
            }
            //
            byte[] bytes =str.getBytes();
            fos.write(bytes, 0, bytes.length);
            System.out.println("复制完成!");
            fos.flush();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            try {
                fos.close();
                fis.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

原文地址:https://www.cnblogs.com/qq993411626------/p/10484642.html