关于JAVA_IO流的一些总结

来源:互联网 发布:js图片重力感应 编辑:程序博客网 时间:2024/05/20 09:07
    FileOutputStream fos = null;//先确定输入输出的用的方法    FileOutputStream fos2 = null;    FileInputStream fis = null;    try{//文件位置写的是src/。。。。。 如果是读取那么必须有源文件     如果**写入**没有源文件则程序会创建一个        fis = new FileInputStream(new File("src/nine/hongli"));        fos = new FileOutputStream(new File("src/nine/hongli1"));        fos2 = new FileOutputStream(new File("src/nine/hongli2"));        byte[] buff = new byte[128];        int temp = 128;        while((temp=fis.read(buff))!=-1){        //重点read中什么都没有则读取一个字节//详情见IO流 read的三种用法        //byte[] 则 读取 数组长度个字节数据并且放在buff中        //temp 为读取的元素个数            fos.write(buff,0,temp);//重点             //写入buff里面的所有元素,从0到temp个            fos2.write(buff,0,temp);        }        fos.flush();        //每次写入都要更新    }catch(Exception e){    }finally{            try {                if(fis==null) fis.close();                if(fos==null) fos.close();            } catch (IOException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }    }}

}