zoukankan      html  css  js  c++  java
  • 字节流复制文件

    方法一:
    package cn.lideng.demo2;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class Copy {
        public static void main(String[] args) throws FileNotFoundException {
            //建立两个交流对象    绑定数据源和目的地
            FileInputStream fis=null;
            FileOutputStream fos=null;
            
            fis=new FileInputStream("d:\b.txt");
            fos=new FileOutputStream("c:\b.txt");
            
            int len=0;
            try {
                while((len=fis.read())!=-1){
                    fos.write(len);
                }
            } catch (IOException e) {
                System.out.println("文件复制失败");
            }
            finally{
                if(fos!=null){
                    try {
                        fos.close();
                    } catch (Exception e2) {
                        // TODO: handle exception
                    }
                    finally{
                        if(fis!=null){
                            try {
                                fis.close();
                            } catch (Exception e3) {
                                e3.printStackTrace();
                                System.out.println("释放资源失败");
                            }
                        }
                    }
                }
            }
            
        }
    
    }
    
    
    
    
    方法二:
    
    package cn.lideng.demo2;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class CopyArr {
        public static void main(String[] args) {
            long c = System.currentTimeMillis();
            FileInputStream fis=null;
            FileOutputStream fos=null;
            
            try {
                fis=new FileInputStream("d:\b.txt");
                fos=new FileOutputStream("c:\b.txt");
                byte[] b=new byte[1024];
                int len=0;
                while((len=fis.read(b))!=-1){
                    fos.write(b,0,len);
                }
                
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{
                if(fos!=null){
                    try {
                        fos.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }finally{
                        if(fis!=null){
                            try {
                                fis.close();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                throw new RuntimeException("释放资源失败");
                            }
                        }
                    }
                }
                long e=System.currentTimeMillis();
                System.out.println(e-c);
            }
        }
    
    }
  • 相关阅读:
    导出报ora-31634、ora-31664
    A significant part of sql server process memory has been paged out
    解决ora-02429:无法用于删除强制唯一/主键的索引
    更改数据库表中有数据的字段类型NUMERIC(18,2)为NUMERIC(18,6)
    GHOST CLEANUP Process
    oracle查看执行计划explain plan FOR
    ORA-01502: 索引或这类索引的分区处于不可用状态
    mysql 游标循环,嵌套游标循环
    MSSQL FOR XML PATH ('')用法
    Mysql CHARINDEX用法
  • 原文地址:https://www.cnblogs.com/qurui1998/p/10595884.html
Copyright © 2011-2022 走看看