what is the difference in using InputStream instead of FileInputStream while creating the FileInputStream object

后端 未结 5 966
天涯浪人
天涯浪人 2021-02-02 13:54

This may be a silly one, but I want to know the background operation difference.

  1. InputStream is = new FileInputStream(filepath);
  2. FileIn
5条回答
  •  伪装坚强ぢ
    2021-02-02 14:25

    FileInputStream extends InputStream: it is a specialized version of an InputStream designed for reading files.

    There are several implementations of an InputStream according to the use of it.

    It is usually good practice to use the highest type needed in your code. Therefore if your code needs to read data from an InputStream but not specifically from a FileInputStream, you should use InputStream. Yet if you do need to keep the information of your object being a FileInputStream and not just an InputStream, then you should keep the FileInputStream type.

提交回复
热议问题