io-byte input stream-fileinputstream

Source: Internet
Author: User

io- byte input stream -fileinputstream

java.io

Class FileInputStream

public class FileInputStream extends InputStream

FileInputStream Gets the input bytes from a file in the file system. Which files are available depends on the host environment.

The FileInputStream is used to read raw byte streams such as data. To read a character stream, consider using filereader.


22-io- copying pictures -copypic

 package day20.io.p2.copypic;     import java.io.BufferedInputStream;     import java.io.BufferedOutputStream;    import  java.io.fileinputstream;    import java.io.fileoutputstream;     import java.io.ioexception;         public class  copypictest {    private static fileinputstream fis;     private static FileOutputStream fos;          public static void main (String[] args)  throws IOException {         copypic4 ();          }         PUBLIC STATIC VOID COPYPIC4 ()  throws  Ioexception {        //buffer array in the byte stream buffer is possible, you can also use the Flush method, the buffer array of data brush out,      The    //flush method is valid in the buffer, and if the file is manipulated directly, Fos.flush () is ineffective          fis = new fileinputstream ("temp\\0.jpg");         Fos = new fileoutputstream ("temp\\4.jpg");         Bufferedinputstream bufis =new bufferedinputstream (FIS);         bufferedoutputstream bufos =new bufferedoutputstream (FOS);         byte[] byt = new byte[1024];         while ((Bufis.read (byt))!=-1) {             bufos.write (byt);             bufos.flush ();      &Nbsp;  }        bufos.close ();         bufis.close ();    }    /*      * COPYPIC3 () This method is not available and is inefficient.      */    PUBLIC STATIC VOID COPYPIC3 ()   throws ioexception {        fis = new  FileInputStream ("temp\\0.jpg");        fos = new  FileOutputStream ("temp\\3.jpg");        int by = 0;         while ((By = fis.read ())!=-1) {         fos.write (by);}         //disk tunnels running in the same place can be bad.         }                 public static void copypic2 ()  throws  Ioexception {        fis = new fileinputstream (" Temp\\0.jpg ");         fos = new fileoutputstream (" Temp\ \2.jpg ");        bufferedinputstream bufis =new  Bufferedinputstream (FIS);        bufferedoutputstream bufos  =new bufferedoutputstream (FOS);        int by = 0;         while ((By = bufis.read ())!=-1) {             bufos.write (by);         }        bufos.close ();         bufis.close ();      }         /*     *   Copy a picture      * 1. Both read and write,      * 2. or non-text data       *     both pictures and text, using the word stream      */     public static void copypic1 ()  throws IOException {         //   1. Identifying data sources and data purposes          Fis = new fileinputstream ("temp\\0.jpg");         fos  = new fileoutputstream ("temp\\1.jpg");         //2. Custom Buffers         byte[] buf = new byte[1024];         int len = 0;         while ((LEN =&NBsp;fis.read (BUF))!=-1) {            fos.write (buf, 0,len);        }         Fos.close ();         fis.close ();     } }



io-byte input stream-fileinputstream

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.