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

如何通過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://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è)
欧美国产日韩一区在线观看| 少妇高潮试看二十分钟| 国产在线拍揄自揄视频不卡99| 日本性电影一区二区| 国产又粗又长又大又长| 婷婷五五月深爱开心激情| 毛片一区二区三区免费看| 五十路八十路息与子交尾| 国产91人妻精品一区二区三区| 亚洲欧美日韩国产一区| 亚洲热久久国产经典视频| 国产女技师口爆在线观看| 国产欧美日韩国产欧美日| 精品亚洲第一区二区免费在线| 日韩最新人妻在线不卡| 日本久久精品视频一区| 中文字幕不卡一区在线| 欧美老熟妇一区三区精品| 国产高清毛片区1区二区三区| 日本不卡一区二区在线播放 | 亚洲国产日韩欧美视频| 美女丝袜诱惑国产91| 可以看黄片的在线观看| 色综合视频二区偷拍在线| 少妇精品偷拍高潮少妇在线观看| 熟妞人妻精品一区二区视频| 亚洲欧美午夜激情啪啪视频| 99久久热这里只有精品| 精品人妻一区二区三区mp4| 久久夜色精品亚洲国产| 九九在线免费视频蜜臀| 亚洲天堂,男人的天堂| 亚洲一区二区三区av电影| 蜜桃视频在线观看91| 国产美女极度色诱视频| 99热在线精品国产观看| 国产三级三级三级免费看| 中文字幕一区中出爽亚洲| 一本色桃子精品久久中文字幕| 伊人青草免费在线视频| 色婷婷av一区二区三|