Java Learning Notes (iv)

Source: Internet
Author: User

 1 package CopyFile; 2 3 Import Java.io.FileInputStream; 4 Import java.io.FileNotFoundException; 5 Import Java.io.FileOutputStream; 6 Import java.io.IOException; 7 8/** 9 * Implement file copy * @author Administrator11 *12 */13 public class CopyFile {+ public static void Copybytesfil E (String sfilename,string dfilename) throws ioexception{15 16//create file input stream object and file output stream object 17//File input stream object and source text FileInputStream fis = new FileInputStream (sfilename); 19//File output stream object associated with the target file FileOutputStream FOS = new FileOutputStream (dfilename); 21//loop reads the contents of the file, and writes out to the external disk file in int read = Fis.read ();//reads a byte from the associated source file, If the end of the file is reached, the return value is -123 while (read! =-1) {fos.write (read);//write a byte to the associated target file. Read = Fis.read () ; 26}27//empty cache Close Stream object Fis.close (); Fos.close ();}31 Public Stat         IC void CopyBytesFile2 (String sfilename,string dfilename) throws ioexception{33 34    Create file input stream object and file output stream object 35//file input stream object associated with source file FileInputStream fis = new FileInputStream (sfilename); 3 7///file output stream object associated with target file FileOutputStream fos = new FileOutputStream (dfilename); 39//Cyclic reading Byte[] B = new BYTE[1024];41/* Read multiple bytes from the associated source file, and save it to byte array b if the end of the file is reached. 42 * The return value is-1, otherwise the return value is the number of bytes actually read.                 */44 int read = Fis.read (b);//Read a byte from the associated source file, and if it reaches the end of the file, the return value is -145 while (read! =-1) {46 Fos.write (b);//write a byte to the associated target file. Read = Fis.read (b); 48}49//Empty cache off Stream object Fis.close (); Fos.close ();}53/**54 * @param args55 */56-PU Blic static void Main (string[] args) {//TODO auto-generated method stub59 long t1,t2;60 t1 = S Ystem.currenttimemillis (); try {copyfile.copybytesfile2 ("A.mp3", "Temp.mp3");(IOException e) {//TODO auto-generated catch block65 e.printstacktrace ();}67 t2 = system.cu Rrenttimemillis (); System.out.println ("Spents:" + (T2-T1)); 69 70}71 72}

Elapsed time Comparison:

Final Job Planning:

Make a video player similar to the following

Implementation features:

Play local video

Play/Pause

Fast Forward/Rewind

Sound adjustment

Fullscreen

Minimize/Maximize/close

Group members: Guo Qiang Cheng Wangyu Lotus

Java Learning Notes (iv)

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.