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();
            }
            
        }

    }

  • 相关阅读:
    卡片式电脑介绍
    怎样对ListView的项进行排序
    jsp 声明类的使用
    Linux下启用Chrome/Firefox的Java插件
    strcmp函数和strcpy函数
    Python+Django+SAE系列教程9-----Django的视图和URL
    美团面试,面一次,累一次
    关于 Head First SQL 中文版
    Linux 内核的编译系统
    简单的REST的框架实现
  • 原文地址:https://www.cnblogs.com/nickhan/p/4226789.html
Copyright © 2011-2022 走看看