Java byte stream

Source: Internet
Author: User

Tag:java    byte stream    

/* bytes Stream Inputstreamoutputstream byte throttle buffer bufferedinputstreambufferedoutputstreamsystem.out: corresponding to the standard output device, console system.in: Corresponding standard input device, keyboard InputStreamReader: Character stream converted to byte stream, byte stream and its buffer no ReadLine method, first changed to character stream buffer */package Pack;import Java.io.bufferedinputstream;import Java.io.bufferedoutputstream;import Java.io.bufferedreader;import Java.io.fileinputstream;import Java.io.fileoutputstream;import Java.io.ioexception;import Java.io.InputStream; Import Java.io.inputstreamreader;public class Main {public static void sys (Object obj) {System.out.println (obj    );        } public static void Main (string[] args) throws IOException {//method1 ();        Method2 ();        Method3 ();        METHOD4 ();    Method5 ();        } public static void Method1 () throws IOException {FileOutputStream fos = new FileOutputStream ("E:\\1.txt");    Fos.write ("abc". getBytes ());//write method does not have string parameters, convert to byte array//stream does not need to refresh fos.close (); } public static void Method2 () throws IOException {FILEINPUTSTReam FIS = new FileInputStream ("E:\\1.txt");        /*int ch = 0;             while ((Ch=fis.read ())!=-1)//Read one sys ((char) ch) at a time;        Fis.close (); */byte[] buf = new Byte[fis.available ()];//fis.available is the number int len = 0;        while ((Len=fis.read (BUF))!=-1) sys (new String (Buf,0,len));        Fis.close (); }/* Copy picture, byte stream */public static void Method3 () throws IOException {FileOutputStream fos = new FileOutputStream (        "E:\\2.jpg");        FileInputStream fis = new FileInputStream ("e:\\1.jpg");        int ch = 0;        while ((Ch=fis.read ())!=-1) fos.write (CH);        Fos.close ();    Fis.close (); }/* Copy MP3, through buffer */public static void Method4 () throws IOException {Bufferedoutputstream bufos=new Bufferedou        Tputstream (New FileOutputStream ("E:\\2.mp3"));        Bufferedinputstream bufis=new Bufferedinputstream (New FileInputStream ("E:\\1.mp3"));        int ch = 0; while ((Ch=bufis.read ())!=-1) BUFos.write (CH);        Bufis.close ();    Bufos.close (); } public static void Method5 () throws IOException {//byte stream and its buffers do not have ReadLine method, first into a character stream buffer inputstream in = Syst em.in; Get keyboard Input Object InputStreamReader ISR = new InputStreamReader (in);//byte stream converted to character stream BufferedReader Bufr = new Bufferedr Eader (ISR);        Character stream buffer string line = NULL;            while ((Line=bufr.readline ())!=null) {if (Line.equals (' over ')) break;        SYS (line);    } bufr.close (); }}

Java 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.