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

      /** 

       * 下载本地文件 

       * @author 柳松 

       * @date 2015-12-30 下午3:27:02 

       * @throws Exception 

       */  

      private static void downLoadLocalFile() throws Exception{  

          File file = new File("D:/file/1.txt");  

          FileInputStream in = new FileInputStream(file);  

      //定义输出的路径  

          File saveDir = new File("D:/file/fileCopy");  

      if (!saveDir.exists()) {  

              saveDir.mkdirs();//创建多重目录  

          }  

          FileOutputStream os = new FileOutputStream(saveDir+"/"+file.getName());  

      //创建缓冲区  

      byte buffer[] = new byte[1024];  

      int len = 0;  

      // 循环将输入流中的内容读取到缓冲区当中  

      while ((len = in.read(buffer)) > 0) {  

             os.write(buffer, 0, len);  

          }  

          in.close();  

          os.close();  

      } 

     

      /** 

           * 下载网络文件 

           * @author 柳松 

           * @date 2015-12-30 下午3:27:19 

           * @throws Exception 

           */  

      private static void downLoadRemoteFile() throws Exception{  

              URL url = new URL("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png");  

              InputStream in = url.openStream();  

      //定义输出的路径  

              File saveDir = new File("D:/file/fileCopy");  

      if (!saveDir.exists()) {  

                  saveDir.mkdirs();//创建多重目录  

              }  

              FileOutputStream os = new FileOutputStream(saveDir+"/"+"downLoad.jpg");  

      //创建缓冲区  

      byte buffer[] = new byte[1024];  

      int len = 0;  

      // 循环将输入流中的内容读取到缓冲区当中  

      while ((len = in.read(buffer)) > 0) {  

                  os.write(buffer, 0, len);  

              }  

              in.close();  

              os.close();  

          } 

  • 相关阅读:
    宝塔面板定时/同步备份网站及数据库至FTP存储空间完整教程
    Heroku是部署又是网站空间? github是仓库
    python批量添加hexo文章封面
    hexo史上最全搭建教程
    小皮面板一款好像还不错的 Linux 管理面板
    [Python] Hexo博文图片上传图床并自动替换链接的Python脚本
    5分钟搞定个人博客-hexo
    python的嵌入式开发
    Windows Embedded CE 6.0开发环境的搭建(2)
    EPLAN中的edz文件的用法
  • 原文地址:https://www.cnblogs.com/zhaoleigege/p/7595906.html
Copyright © 2011-2022 走看看