• 文件的复制


      /** 

       * 下载本地文件 

       * @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();  

          } 

  • 相关阅读:
    MQ 2035(MQRC_NOT_AUTHORIZED)
    C# 构造函数中调用虚方法的问题
    Oracle bug 使用max或min函数into到一个char类型报字符缓冲区太小的错误
    windows2003 64位 iis6.0 运行32位web应用程序
    .NET安装和配置Oracle数据访问组件(ODAC)
    WMS函数组:10.创建采购订单
    报表:BOM展开程序
    WMS函数组:9.交货单过帐3(BDC)
    WMS函数组: 7.交货单行项目除
    WMS函数组:1.检查ZPB2是否存在
  • 原文地址:https://www.cnblogs.com/zhaoleigege/p/7595906.html
Copyright © 2020-2023  润新知