欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java中如何使用字節(jié)流復(fù)制文件

這篇文章將為大家詳細(xì)講解有關(guān)java中如何使用字節(jié)流復(fù)制文件,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),海州企業(yè)網(wǎng)站建設(shè),海州品牌網(wǎng)站建設(shè),網(wǎng)站定制,海州網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,海州網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

以前在學(xué)校,為了準(zhǔn)備某個(gè)證書(shū)考試,預(yù)習(xí)的時(shí)候?qū)懙摹](méi)什么技術(shù)含量,主要是熟悉一下,j2se中基本控件的操作,以及事件的綁定,等等。

Example:

import java.io.*;  import java.util.Scanner;  /**   * java使用字節(jié)流復(fù)制圖像   * @author Administrator   *@time 2011年6月9日 19:55:10   */public class MyTest2 {        private String filename;  //文件名         private  double  filesize;       //文件大小       public static void main(String agrs[]){        MyTest2 tt2=new MyTest2();        String frompath="E:\\qq.png";        String topath="F:\\qq.png";        if(tt2.CheckFile(frompath, topath)){        tt2.CopyFile(frompath, topath);          }      }      //復(fù)制文件      public void  CopyFile(String frompath,String topath){          File file1=new File(frompath);//源文件路徑          File file2=new File(topath);//目標(biāo)文件路徑          filename=file1.getName();          filesize=(file1.length())/1024/1024;          System.out.println("********************文件屬性********************");          System.out.println("源文件路徑:"+frompath);          System.out.println("目標(biāo)文件路徑:"+topath);          System.out.println("文件名稱:"+filename);        System.out.println("文件大小:"+filesize+" MB");          int ch=0;          try{              FileInputStream fin=new FileInputStream(file1);              FileOutputStream fout=new FileOutputStream(file2);              ch=fin.read();              System.out.println("開(kāi)始復(fù)制!");            long startTime=System.currentTimeMillis();   //獲取開(kāi)始時(shí)間              while(ch!=-1){                  fout.write(ch);                  ch=fin.read();              }              long endTime=System.currentTimeMillis(); //獲取結(jié)束時(shí)間              System.out.println("程序運(yùn)行時(shí)間: "+(endTime-startTime)+"ms");              System.out.println("復(fù)制完畢!");              //關(guān)閉流              fin.close();                fout.close();          }  catch(Exception e){              System.err.println("Error:  "+e);         }         }     //驗(yàn)證文件是否存在      public boolean CheckFile(String frompath,String topath){          File file1=new File(frompath);//源文件路徑          File file2=new File(topath);//目標(biāo)文件路徑          if(!file1.exists()){                      //文件不存在                 System.out.println("源文件不存在,請(qǐng)檢查路徑是否正確!");              return false;          }  else{              if(file2.exists()){                  System.out.println("目標(biāo)文件已經(jīng)存在,請(qǐng)選擇  覆蓋/取消  ?");                  System.out.println("1: 覆蓋    2:取消");                  try{                      Scanner sc=new Scanner(System.in);                      int a=sc.nextInt();                      if(a==1){                          System.out.println("你輸入的是1,操作將繼續(xù),目標(biāo)文件將被覆蓋。");                          return true;                      }else if(a==2){                          System.out.println("您輸入了2,操作將取消。");                          return false;                      }  else{                      System.out.println("輸入無(wú)效。。;");                      CheckFile(frompath, topath);                 return false; }                  }   catch(Exception ee){                      System.out.println("輸入無(wú)效。。;");                      CheckFile(frompath, topath);                      return false;                  }              }          }          return false;    }  }

java中如何使用字節(jié)流復(fù)制文件

關(guān)于“java中如何使用字節(jié)流復(fù)制文件”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

本文題目:java中如何使用字節(jié)流復(fù)制文件
本文路徑:http://www.chinadenli.net/article24/geeice.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃營(yíng)銷型網(wǎng)站建設(shè)動(dòng)態(tài)網(wǎng)站靜態(tài)網(wǎng)站域名注冊(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)