package cn.donglinode.IO;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Copy01 {
public static void main(String[] args) {
FileInputStream fis=null;
FileOutputStream fos=null;
try {
//输入流
fis=new FileInputStream("E:\\bean.xml");
//输出流
fos=new FileOutputStream("F:\\bean.xml",true);
byte[] bytes=new byte[1024];
int readCount=0;
while((readCount=fis.read(bytes))!=-1){
//写出
fos.write(bytes,0,readCount);
//刷新,这个步骤要有,否则可能会出现数据丢失
fos.flush();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
//关闭输入流和输出流,切记要分开关闭,如果放一起关闭,一旦有一个抛出异常,下一个就关不了了。
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos!=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}