--Record specified path copy file to another path

Source: Internet
Author: User

/*** Copy media files, this example is a copy of the 1.mp3 file, listed in four ways.*/ImportJava.<a href= "https://www.baidu.com/s?wd=io&tn=44039180_cpr&fenlei= Mv6quakxtzn0izrqihckpjm4nh00t1y4uhdlnyfzujblp1d3ujr10zwv5hcvrjm3rh6spfkwumw85hfynjn4nh6sgvpst6kdthsqpzwytjceqlgcpyw9uz4bm Y-bii4wuvyetgn-tlwguv3epw6ln1t3phrsphczn1r1phmy "target=" _blank "class= "Baidu-highlight" >io</a>. Bufferedinputstream;ImportJava.<a href= "https://www.baidu.com/s?wd=io&tn=44039180_cpr&fenlei= Mv6quakxtzn0izrqihckpjm4nh00t1y4uhdlnyfzujblp1d3ujr10zwv5hcvrjm3rh6spfkwumw85hfynjn4nh6sgvpst6kdthsqpzwytjceqlgcpyw9uz4bm Y-bii4wuvyetgn-tlwguv3epw6ln1t3phrsphczn1r1phmy "target=" _blank "class= "Baidu-highlight" >io</a>. Bufferedoutputstream;ImportJava.<a href= "https://www.baidu.com/s?wd=io&tn=44039180_cpr&fenlei= Mv6quakxtzn0izrqihckpjm4nh00t1y4uhdlnyfzujblp1d3ujr10zwv5hcvrjm3rh6spfkwumw85hfynjn4nh6sgvpst6kdthsqpzwytjceqlgcpyw9uz4bm Y-bii4wuvyetgn-tlwguv3epw6ln1t3phrsphczn1r1phmy "target=" _blank "class= "Baidu-highlight" >io</a>. FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classBufferedstreamcopyfiles { Public Static voidMain (string[] args)throwsIOException {/*** There are four methods, but it is recommended to use DEMO1,DEMO2; because DEMO3 need to create an array, if the file is large, it takes a lot of time for the light to create an array, and Demo4 must not be used, * the efficiency is very slow. */demo1 ();        Demo2 ();        Demo3 ();     Demo4 (); }      Public Static voidDemo1 ()throwsFileNotFoundException, IOException {fileinputstream fis=NewFileInputStream ("D:\\1.mp3"); FileOutputStream Fos=NewFileOutputStream ("D:\\01.mp3"); intLen = 0; byte[] buf =New byte[1024];  while(len = Fis.read (BUF))! =-1) {fos.write (buf,0, Len);        } fis.close ();    Fos.close (); }      Public Static voidDemo2 ()throwsIOException {fileinputstream fis=NewFileInputStream ("D:\\1.mp3"); Bufferedinputstream Bufis=NewBufferedinputstream (FIS); FileOutputStream Fos=NewFileOutputStream ("D:\\02.mp3"); Bufferedoutputstream Bufos=NewBufferedoutputstream (FOS); intLen = 0;  while(len = Bufis.read ())! =-1) {bufos.write (len);        } bufis.close ();    Bufos.close (); }     //not recommended in this way     Public Static voidDemo3 ()throwsIOException {fileinputstream fis=NewFileInputStream ("D:\\1.mp3"); FileOutputStream Fos=NewFileOutputStream ("D:\\03.mp3"); byte[] buf =New byte[Fis.available ()];        Fis.read (BUF);        Fos.write (BUF);        Fos.close ();     Fis.close (); }      Public Static voidDemo4 ()throwsIOException {fileinputstream fis=NewFileInputStream ("D:\\1.mp3"); FileOutputStream Fos=NewFileOutputStream ("D:\\04.mp3"); intCH = 0;  while(ch = fis.read ())! =-1) {fos.write (CH);        } fos.close ();    Fis.close (); }}

--Record specified path copy file to another path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.