byte stream of JAVA IO stream

Source: Internet
Author: User

Byte stream two base class InputStream   Read OutputStream   write   character stream two base classes readerwriter  These four abstract classes are derived from the subclass of the parent class as a subclass suffix   OutputStream Basic method: Close () flush () write ()   parameter: byte[]  b,int B inputstream Basic method Read () int avaliable ()   Returns the number of bytes remaining in the file. That is, the size of the file, so that you can define an array to fit the data exactly. But the amount of data is too large to use the buffer of the    byte stream: Bufferedoutputstream (OS Stream object) write () method  bufferedinputstream (Oi Stream object) Read () method        Example application: Import java.io.*;p ublic class Test {  public static void main ( String[] args) throws ioexception {   fileoutputstream fo = new FileOutputStream ("c:\\users\\zx\\ Desktop\\zx.txt ");   fo.write (" ABCDE ". GetBytes ());   //does not need to be refreshed, it can be displayed.    fo.close ();      fileinputstream fl = new FileInputStream ("c:\\users\\zx\\desktop\\ Zx.txt ");      int ch=0;   while ((Ch=fl.read ())!=-1)    {    SOP ( Fl.available ());    SOP ((char) ch);   }     &NBsp; } public static void sop (Object obj)  {  System.out.println (obj); }}  Picture file copy application Import java.io.*;p ublic class Test {  public static void main (string[] args) throws ioexception {   FileOutputStream fo=null;  FileInputStream  fi = null;  try  {  fo = new FileOutputStream ( "D://2.png");  fi = new FileInputStream ("D://1.png");  byte [] b = new byte[1024];  int len = 0;  whil E ((Len=fi.read (b))!=-1)   {   fo.write (b,0,len); } }  catch (IOException e)   {  }  finally  {    fi.close ();    fo.close (); }     }  public static void sop (Object obj)  {  System.out.println (obj); }} 

Byte stream of JAVA io 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.