zoukankan      html  css  js  c++  java
  • io流

    package com.io;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    public class Test2 {
    
        /**
         * @param args
         * @throws IOException 
         */
        public static void main(String[] args)  {
           
            File file1 = new File("C:\Users\Coda\Desktop\google1.jpg");
            File file2 = new File("C:\Users\Coda\Desktop\图片储存\dd.jpg");
            
                CopyIt(file1,file2);
            
        }
        
        public static void CopyIt( File file1, File file2) {
    
            FileInputStream fileInputStream;
            try {
                fileInputStream = new FileInputStream(file1);
            } catch (FileNotFoundException e) {
                System.out.println("文件路径错误");
                 throw new RuntimeException(e);
            }
            FileOutputStream fileOutputStream = null;
            try {
                fileOutputStream = new FileOutputStream(file2,true);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
            byte[]b = new byte[2];
            int count = 0;
            try {
                while((count = fileInputStream.read(b))!=-1){
      
                    fileOutputStream.write(b);
          
                }
            } catch (IOException e) {
                  System.out.println("写入文件失败");
                throw new RuntimeException(e);
                
            } finally{
                  try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    System.out.println("文件正在运行,无法关闭");
                    throw new RuntimeException(e);
                }
                   try {
                    fileInputStream.close();
                } catch (IOException e) {
                    System.out.println("文件正在运行,无法关闭");
                    throw new RuntimeException(e);
                }  
                System.out.println("文件复制成功");
            }
                
      }
    
    }
  • 相关阅读:
    使用命令xrandr设置当前系统的显示分辨率及显示的旋转脚本
    CODEFORCE 246 Div.2 B题
    Android数据的四种存储方式之SQLite数据库
    C语言默认參数值的实现
    Android开发环境搭建
    也谈OpenFlow, SDN, NFV
    解决设置redmineblacklog的按钮无效问题
    长方体的研究
    表面张力与浮力
    表面张力与浮力
  • 原文地址:https://www.cnblogs.com/chEnYoNg11/p/6181854.html
Copyright © 2011-2022 走看看