The main points of

Is the parent class of all byte input streams, and subclasses of its methods (FileInputStream, etc.) can use it.

Method of use

  • The first constructor FileInputStream(String(File))// The destination (path) of the File to read
  • Int read()// One byte at a time, returns an int, or -1 if not read, like Next(), moves the pointer one bit further back
  • Read (byte[] b)// Read multiple bytes at a time
  • The String class has a constructor: String(btye []), which turns bytes into strings

Use cases

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;

public class InputS {
    public static void main(String[] args) throws IOException {
        File file = new File("D: \ \ JavaSE based grammar \ \ \ \ SRC \ \ com \ \ JavaSE \ \ CommonAPI \ \ a.t xt." ");
        FileInputStream fileIn = new FileInputStream(file);
        byte [] bytes = new byte[(int)file.length()];// The size of the file is the size of the array, because length returns long, requires type conversion
        int re = 0;//
        int i = 0;
        while((re=fileIn.read())! = -1){
            bytes[i++] = (byte) re;// Convert files to byte arrays,
        }
        String s = new String(bytes);// Convert the byte array to a StringSystem.out.println(s); }}Copy the code