/*** 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