Java IO stream (byte stream) copy file

Source: Internet
Author: User
Tags file copy

Java IO stream (byte Stream)

Copying files

//Copying Files//using byte streams//copy text file with character stream, copy other format file with byte streamImportJava.io.*; public classindex{ public Static voidMain (string[] Args)throwsexception{//character Stream mode//FileReader FZ = new FileReader ("e:/1.txt"); //FileWriter zt = new FileWriter ("e:/2.txt"); //byte stream modeFileInputStream FZ =NewFileInputStream ("d:/kugou/liu huan-on the way. mp3"); FileOutputStream ZT=NewFileOutputStream ("d:/223.mp3"); intaa; intFz_size = 0;//How big is the statistical file ?AA = Fz.read ();//Read 1 bytes         while(aa!= (-1) ) {zt.write (aa);//Write 1 bytesAA = Fz.read ();//Continue reading 1 bytesfz_size++; }                //output all remaining content in the stream//when copying a file, write this before closing the file to fully copy the fileZt.flush ();        Fz.close ();                Zt.close (); System.out.println ("file copy succeeded, total" +fz_size+ "bytes"); }}

Java IO stream (byte stream) copy file

Related Article

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.