Java serializes 96 FileInputStream method to parse and loop out all contents


1、 Analyze the available / skip / close / read (int [] a) method and use the read method to print out all the contents.


package com.bjpowernode.java_learning;


public class D96_1_CircleRead {

  public static void main(String[] args) throws Exception{

    FileInputStream fis = new FileInputStream("C:\Users\lenovo1\Workspaces\MyEclipse CI\Java_learning\src\com\bjpowernode\java_learning\");

    byte[] bytes = new byte[1024];

    //1. Available method



    //2. Skip method

    fis.skip (2) ; // skip reading two bytes


    //3. Print the content circularly

    while(true) {

      int temp =;

      if(temp==-1) break;

      //Converts valid data in byte array to string

      System.out.print(new String(bytes,0,temp));

      //Note that here is the string interception. We need to know the return value of the read method here, so it is equivalent to creating an array to store each time

      //Read 1KB, then 1KB, 1KB output. The reason why I use 0 to temp is that I can fill the array when I read it, but when I read it, I can fill the array

      //At the last moment, a part of the array will be occupied. If we use fixed length 1024, we will print out the last part of the content



    //4. Int read (byte [] b) reads data of up to b.length bytes from input stream into byte array



    //As you can see, the available method is used to see how many bytes are left unread


    //5. Remember to close the stream






2、 Source code:


3. Blog Garden:

4. welcome to WeChat official account: Fourier transform, official account number, only for learning communication, background reply, “gift package”, get big data learning materials.