Java IO input-output stream FileWriter character stream

Source: Internet
Author: User
Tags wrapper

BYTE buffer stream

Why use wrapper flows, which are used to improve the performance of read and write operations. public class Packing_flowdemo {public static void main (string[] args) throws Exception {File File = new file ("File/packing _flow.txt ");//The notation of the wrapper stream, the buffer memory size. 1024*8=8192  (byte)//bufferedoutputstream packing = new Bufferedoutputstream (new FileOutputStream (file, True));// Packing.write ("Hello everyone!") How are you? How is your! ". GetBytes ());//packing.close ();     The read and write operation of the wrapper stream. Bufferedinputstream outpacking = new Bufferedinputstream (new FileInputStream (file)); byte[] buffer = new Byte[1024];int Len = -1;while ((len = outpacking.read (buffer))! =-1) {System.out.println (new String (buffer, 0, Len));}}}

public static void Main (string[] args) throws IOException {//For the code to look good, throw it directly out of file File=new file ("moves/Xu Song-makeup-field edition. mp3" ); File File1=new file ("moves/Xu Song-makeup. mp3"),//text (file, file1),//text2 (file, file1),//text3 (file, file1); Text4 (file, FILE1);} private static void text (File file,file file1) throws IOException {///node stream method, one byte read and write Long begin= System.currenttimemillis (); FileInputStream in=new fileinputstream (file); FileOutputStream out =new FileOutputStream (file1); int Len=-1;while ((Len=in.read ())!=-1) {out.write (len); In.close (); Out.close (); System.out.println (System.currenttimemillis ()-begin)//5547 milliseconds}private static void Text2 (File file,file file1) throws IOException {//Buffer stream notation, one byte read and write Long Begin=system.currenttimemillis (); Bufferedinputstream in=new Bufferedinputstream (new FileInputStream (file)); Bufferedoutputstream out =new Bufferedoutputstream (new FileOutputStream (file1)); int Len=-1;while (In.read ()!=-1) { Out.write (len);} In.close (); Out.close (); System.out.println (System.currenttimemillis ()-begin)//63 ms}private static void Text3 (File file,file file1) throws IOException {///node stream notation, one-time read 1024 bytes long begin= System.currenttimemillis (); FileInputStream in=new fileinputstream (file); FileOutputStream out =new FileOutputStream (file1); int len=-1;byte[] Buffer=new byte[1024];while ((len=in.read (buffer) ) {!=-1) {out.write (Buffer,0,len);} In.close (); Out.close (); System.out.println (System.currenttimemillis ()-begin)//38 milliseconds}private static void Text4 (File file,file file1) throws IOException {//Buffer stream notation, one-time read 1024 bytes long begin=system.currenttimemillis (); Bufferedinputstream in=new Bufferedinputstream (new FileInputStream (file)); Bufferedoutputstream out =new Bufferedoutputstream (new FileOutputStream (file1)); int len=-1;byte[] Buffer=new byte[ 1024];while ((len=in.read (buffer))!=-1) {out.write (Buffer,0,len);} In.close (); Out.close (); System.out.println (System.currenttimemillis ()-begin);//4 milliseconds}

Java IO input-output stream FileWriter character stream

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.