欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何通過JAVANIO通道傳輸拷貝文件

這篇文章給大家分享的是有關(guān)如何通過JAVA NIO通道傳輸拷貝文件的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

成都創(chuàng)新互聯(lián)公司是專業(yè)的西吉網(wǎng)站建設(shè)公司,西吉接單;提供成都做網(wǎng)站、成都網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行西吉網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

通過JAVA NIO 通道傳輸拷貝文件

方式一

 /**
   * 通過JAVA NIO 通道傳輸拷貝文件
   *
   * @param sourcePath 源文件路徑
   * @param targetPath 目標(biāo)文件路徑
   */
  public static void copyFileByChannelTransfer(String sourcePath, String targetPath) {
    FileChannel inChannel = null;
    FileChannel outChannel = null;
    try {
      //獲取通道
      inChannel = FileChannel.open(Paths.get(sourcePath), StandardOpenOption.READ);
      outChannel = FileChannel.open(Paths.get(targetPath),StandardOpenOption.WRITE,StandardOpenOption.READ,StandardOpenOption.CREATE);

      inChannel.transferTo(0,inChannel.size(),outChannel);
    } catch (IOException e) {
      e.printStackTrace();
    }finally {
      //關(guān)閉流
      try {
        if (outChannel != null) {
          outChannel.close();
        }
        if (inChannel != null) {
          inChannel.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

方式二

 /**
   * 通過JAVA NIO 通道傳輸拷貝文件
   *
   * @param sourcePath 源文件路徑
   * @param targetPath 目標(biāo)文件路徑
   */
  public static void copyFileByChannelTransfer2(String sourcePath, String targetPath) {
    FileInputStream fis = null;
    FileOutputStream fos = null;
    FileChannel inChannel = null;
    FileChannel outChannel = null;
    try {
      fis = new FileInputStream(sourcePath);
      fos = new FileOutputStream(targetPath);

      //獲取通道
      inChannel = fis.getChannel();
      outChannel = fos.getChannel();

      inChannel.transferTo(0,inChannel.size(),outChannel);
    } catch (IOException e) {
      e.printStackTrace();
    }finally {
      //關(guān)閉流
      try {
        if (outChannel != null) {
          outChannel.close();
        }
        if (inChannel != null) {
          inChannel.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }

使用示例

String source = "e:\\demo\\縱天神帝.txt";
    String target = "e:\\demo\\";
    long time1 = System.currentTimeMillis();
    copyFileByStream(source, target + "1.txt");
    System.out.println("通過字節(jié)流實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time1));

    long time2 = System.currentTimeMillis();
    copyFileByReaderAndWriter(source, target + "2.txt");
    System.out.println("通過字符流實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time2));

    long time3 = System.currentTimeMillis();
    copyFileByBuffered(source, target + "3.txt");
    System.out.println("通過字節(jié)緩沖流實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time3));

    long time4 = System.currentTimeMillis();
    copyFileByBufferedChar(source, target + "4.txt");
    System.out.println("通過字符緩沖流實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time4));

    long time5 = System.currentTimeMillis();
    copyFileByChannel(source, target + "5.txt");
    System.out.println("通過JAVA NIO通道(非直接緩沖區(qū))實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time5));

    long time6 = System.currentTimeMillis();
    copyFileByChannelBufferd(source, target + "6.txt");
    System.out.println("通過JAVA NIO通道(直接緩沖區(qū))實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time6));

    long time7 = System.currentTimeMillis();
    copyFileByChannelTransfer(source, target + "7.txt");
    System.out.println("通過JAVA NIO通道傳輸實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time7));

    long time8 = System.currentTimeMillis();
    copyFileByChannelTransfer(source, target + "8.txt");
    System.out.println("通過JAVA NIO通道傳輸2實(shí)現(xiàn)文件的拷貝耗時(shí):" + (System.currentTimeMillis() - time8));

感謝各位的閱讀!關(guān)于“如何通過JAVA NIO通道傳輸拷貝文件”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

網(wǎng)站題目:如何通過JAVANIO通道傳輸拷貝文件
當(dāng)前鏈接:http://www.aaarwkj.com/article26/igsecg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)站營銷、搜索引擎優(yōu)化、企業(yè)建站、域名注冊(cè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)
日韩av高清在线播放| 九九有点热以前的视频| 亚洲综合欧美日韩一区| 亚洲一二三区精品与老人| 国产大片在线观看一区二区| 欧美色精品人妻在线最新| 青草免费在线播放视频| 日本不卡一区二区三区四| 熟女少妇久久中文字幕| 十八禁一区二区在线观看| 亚洲中国av一区二区| 久久婷婷国产综合精品青草 | 丰满人妻被黑人猛烈进入| 亚洲欧洲精品专线九九| 国产欧美日韩精品av| 日韩欧美中文在线一区二区| 国产视频一区二区三区网| 亚洲av乱码一区二区三四五六七| 人妻艳情一区二区三区| 午夜体内射精免费视频| 欧美二区三区精品在线| 亚洲欧美国产日韩综合在线 | 日韩免费av在线网站| 色自拍偷拍另类欧洲美女| 激情综合五月激情综合| 精品国产视频一区二区三区| 在线观看中文字幕不卡二区| 亚洲日本不卡在线一区二区| 99久久成人国产精品免费| 免费女性啪啪无遮挡网站| 精品人妻一区二区三区蜜桃视频| 俄罗斯少妇毛茸茸的高潮| 亚洲国产成人av精品精品国产自 | 日韩欧美国产精品加勒比| av中文在线免费观看| 亚洲精品影视一区二区| 国产三级三级三级免费看| 天天操天天射夜夜撸| 免费观看在线黄色大片| 91麻豆粉色视频在线| 亚洲av成人在线资源|