zoukankan      html  css  js  c++  java
  • Java复制文件

    public class FileUtil {
        private FileUtil() {
        }

      public static void copyFile(String srcFile,String targetPath){
            File src = new File(srcFile);
            if(!src.exists()){
                System.out.println("文件【"+src+"】不存在");
                return;
            }
            System.out.println("正在复制文件:"+src);
            int byteRead = 0;
            try {
                InputStream in = new FileInputStream(src);
                File tarPath = new File(targetPath);
                if(!tarPath.exists()){//如果目标路径不存在 , 则创建一个目标路径
                    tarPath.mkdir();
                }
                File tar = new File(tarPath.getAbsolutePath(),src.getName());
                FileOutputStream out = new FileOutputStream(tar);
                byte[] b = new byte[1024];//缓存
                while((byteRead = in.read(b))!=-1){    
                    out.write(b,0,byteRead);
                }
                in.close();
                out.close();
                System.out.println("文件复制完成!");
            } catch (Exception e) {
                System.out.println("文件复制失败!");
                e.printStackTrace();
            }
            
        }

    }

  • 相关阅读:
    前端- css
    前端- html -总结
    2016.9.15 黑客编程之无限启动
    2016.9.14 JavaScript入门之七面向对象和函数
    2016.9.13 JavaScript入门之六基础函数
    2016.9.1 JavaScript入门之五
    2016.9.9 网络工程师之路由器技术
    2016.8.14 网络工程师之网关协议
    2016.8.27 JavaScript入门之四
    2016.8.22 JavaScript入门之三
  • 原文地址:https://www.cnblogs.com/nickhan/p/4226789.html
Copyright © 2011-2022 走看看