Dark Horse programmer-byte stream

Source: Internet
Author: User
Package excr19; import Java. io. fileinputstream; import Java. io. fileoutputstream; import Java. io. ioexception;/* thoughts on byte stream media files: 1. use byte to read stream objects and associate images. create an image file by writing bytes to the stream object to store the obtained image data. 3. data storage is completed through cyclic read/write. only copying resources from this disk */public class demo9 {/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubfileoutputstream fileoutputstream = NULL; fileinputstream = NULL; try {File Outputstream = new fileoutputstream ("C: \ Taylor Swift-You belong with me1.mp3"); fileinputstream = new fileinputstream ("C: \ Taylor Swift-You belong with meong "); byte [] Buf = new byte [1024*5]; int Len = 0; while (LEN = fileinputstream. read (BUF ))! =-1) {fileoutputstream. write (BUF, 0, Len) ;}} catch (ioexception e) {Throw new runtimeexception ("failed to copy the file"); // todo: handle exception} finally {try {If (fileinputstream! = NULL); fileinputstream. Close () ;}catch (ioexception e) {Throw new runtimeexception ("failed to read the file") ;}}try {If (fileinputstream! = NULL); fileinputstream. close () ;}catch (ioexception e) {Throw new runtimeexception ("failed to write data") ;}} package excr19; import Java. io. bufferedinputstream; import Java. io. bufferedoutputstream; import Java. io. bufferedwriter; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import Java. io. fileoutputstream; import Java. io. ioexception; public class demo10 {/** map3 copy: Through the buffer * 1. define an array * 2. define pointer * 3. define counter * @ Param ARGs * @ throws ioexception */public static void main (string [] ARGs) throws ioexception {// todo auto-generated method stublong start = system. currenttimemillis (); copy_1 (); long end = system. currenttimemillis (); system. out. println (end-Start) + "millisecond");} // copy public static void copy_1 () throws ioexception {bufferedinputstream = new bufferedinputstream (New filei Nputstream ("C :\\ Taylor Swift-love storystream"); bufferedoutputstream = new bufferedoutputstream (New fileoutputstream ("D: \ Taylor Swift-love story1.mp3 ")); int by = 0; while (by = bufferedinputstream. read ())! =-1) {bufferedoutputstream. write (by);} bufferedoutputstream. close (); bufferedinputstream. close () ;}} package excr19; import Java. io. bufferedreader; import Java. io. ioexception; import Java. io. inputstream; import Java. io. inputstreamreader; public class demo13 {/*** @ Param ARGs * @ throws ioexception */public static void main (string [] ARGs) throws ioexception {// todo auto-generated method stub // obtain the keyboard entry object in Putstream inputstream = system. in; // converts a byte stream object to a bytes Stream object. The conversion rate is inputstreamreaderinputstreamreader inputstreamreader = new inputstreamreader (inputstream). // to improve efficiency, the bytes stream string is used for efficient buffer operations, use bufferedreaderbufferedreader bufferedreader = new bufferedreader (inputstreamreader); string linestring = NULL; while (linestring = bufferedreader. readline ())! = NULL) {If ("over ". equals (linestring) {break;} system. out. println (linestring. touppercase ();} bufferedreader. close () ;}} package excr19; import Java. io. bufferedreader; import Java. io. ioexception; import Java. io. inputstream; import Java. io. inputstreamreader; import Java. io. outputstream; import Java. io. outputstreamwriter; public class demo14 {/*** character to byte * is a character, but it is a byte * @ Param ARGs * @ throws ioexcept Ion */public static void main (string [] ARGs) throws ioexception {// todo auto-generated method stubinputstream inputstream = system. in; inputstreamreader = new inputstreamreader (inputstream); outputstream out = system. out; bufferedreader = new bufferedreader (inputstreamreader); outputstreamwriter = new outputstreamwriter (out); bufferedreader bufferedreader2 = new Bufferedreader (outputstreamwriter); string linestring = NULL; while (linestring = bufferedreader. Readline ())! = NULL) {If ("over ". equals (linestring) {break; outputstreamwriter. write (linestring. touppercase () + "\ r \ n"); outputstreamwriter. flush () ;}} bufferedreader. close ();}}

See http://edu.csdn.net/heima for details

Dark Horse programmer-byte stream

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.