Fourth time assignment

Source: Internet
Author: User

Import java.io.*;PublicClassCopyfile {PublicStaticvoidCopybytesfile(String sfilename,string Dfilename)Throws ioexception{Create a file input stream object and a file output stream object FileInputStream fis=New FileInputStream (sFileName);File input stream object associated with source file FileOutputStream fos=New FileOutputStream (Dfilename);File output stream object associated with target fileUse a loop to read the contents of a file and write it out to an external disk fileReads a byte from the associated source file, if the end of the file is reached, the return value is-1, otherwise the return value is the actual unique number of bytesint Read=fis.read ();while (read!=-1) {fos.write (read);writes out the byte data in the current byte array to the associated target file Read=fis.read ();} Fis.close (); //Empty cache, Close stream object Fos.close ();} public static void main(string[] args) {//TODO auto-generated method stubLong t1,t2;t1= System.currenttimemillis (); try {copyfile.copybytesfile ("A.mp3", "Temp.mp3");} catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();} t2=system.currenttimemillis () ; System.out.println ("spents:" + (T2-T1) +"MS");}}            

Multi-character output

Import Java.io.FileInputStream;Import java.io.FileNotFoundException;Import Java.io.FileOutputStream;Import java.io.IOException;PublicClassCopyfile {PublicStaticvoidCopybytesfile(String sfilename,string Dfilename)Throws ioexception{Creating a file input stream object and a file output stream objectFile input stream object associated with source file FileInputStream fis=New FileInputStream (sFileName);File output stream object associated with target file FileOutputStream fos=New FileOutputStream (Dfilename);Loop through the contents of the file and write it out to the external fileByte[] B=Newbyte[1024*10];Reads a byte from the associated source file, saves it to byte array B, and returns a value of 1 if it reaches the end of the file.int read =fis.read (b);while (read!=-1) {Fos.write (b); //writes out a byte to the associated target file Read=fis.read (b);} //empties the cache, closes the Stream object Fis.close (); Fos.close ();} public static void main (string[] args) { //TODO auto-generated Method stub long t1,t2; t1= System.currenttimemillis (); try {copyfile.copybytesfile ( "A.mp3",  "Temp.mp3"); } catch (IOException e) {//TODO auto-generated Catch block E.printstacktrace (); } t2=system.currenttimemillis (); System.out.println ( "spents:" + (T2-T1));}}         

Fourth time assignment

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.