java io流中节点流与处理流
package javaio;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class 拷贝文件 {
public static void main(String[] args) {
FileInputStream fis =null;
FileOutputStream fos=null;
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try{
fis=new FileInputStream("D:/瀑布.jpg");//节点流创建
bis=new BufferedInputStream(fis);//处理流
fos=new FileOutputStream("D:/FF.jpg");
bos=new BufferedOutputStream(fos);
int temp=0;
//缓冲流中的 byte 数组长度默认是 8192
while((temp=bis.read())!=-1)
{
bos.write(temp);
}
bos.flush();
}catch(Exception e)
{
e.printStackTrace();
}finally {
try {//关闭顺序:后开先关闭,是不是只是基于节点流与处理流之间的比较,节点流与节点流之间没有先后关闭顺序要求,处理流之间同理。
if(bis!=null)
{
bis.close();
}
if(fis!=null)
{
fis.close();
}
if(bos!=null)
{
bos.close();
}
if(fos!=null)
{
fos.close();
}
}catch (Exception e)
{
e.printStackTrace();
}
}
}
}