package day180207;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.management.RuntimeErrorException;
/*
* 文件的复制的学习
*/
public class IoCopyDemo {
public static void main(String[] args) {
//定义两个流对象的变量
FileInputStream fis=null;
FileOutputStream fos=null;
try {
//建立两个流对象,绑定数据源和数据目的
fis=new FileInputStream("J:\\pycharm.txt");
fos=new FileOutputStream("H:\\pycharm.txt");
//字节输入流读一个字节,输出写一个字节
int len=0;
while((len=fis.read())!=-1){
fos.write(len);
}
} catch (IOException ex) {
// TODO: handle exception
System.out.println(ex);
throw new RuntimeException("文件复制失败");
}finally{
try{
if(fos!=null){//先判断输出流有没有建成功,没有成功没必要关闭
fos.close();
}
}catch(IOException ex){
throw new RuntimeException("释放流失败,请重试");
}finally {
try{
if(fis!=null){
fis.close();
}
}catch(IOException ex){
throw new RuntimeException("释放输入流失败,请重试");
}finally{
}
}
}
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.management.RuntimeErrorException;
/*
* 文件的复制的学习
*/
public class IoCopyDemo {
public static void main(String[] args) {
//定义两个流对象的变量
FileInputStream fis=null;
FileOutputStream fos=null;
try {
//建立两个流对象,绑定数据源和数据目的
fis=new FileInputStream("J:\\pycharm.txt");
fos=new FileOutputStream("H:\\pycharm.txt");
//字节输入流读一个字节,输出写一个字节
int len=0;
while((len=fis.read())!=-1){
fos.write(len);
}
} catch (IOException ex) {
// TODO: handle exception
System.out.println(ex);
throw new RuntimeException("文件复制失败");
}finally{
try{
if(fos!=null){//先判断输出流有没有建成功,没有成功没必要关闭
fos.close();
}
}catch(IOException ex){
throw new RuntimeException("释放流失败,请重试");
}finally {
try{
if(fis!=null){
fis.close();
}
}catch(IOException ex){
throw new RuntimeException("释放输入流失败,请重试");
}finally{
}
}
}
}
}