问题描述
这可能是一个愚蠢的,但我想知道背景操作差异。
This may be a silly one, but I want to know the background operation difference.
-
InputStream是= new FileInputStream(filepath);
-
FileInputStream is = new FileInputStream(filepath);
InputStream is = new FileInputStream(filepath);
FileInputStream is = new FileInputStream(filepath);
上述两行代码之间的区别在于它们使用的是什么情况。
What is the difference between the above two lines of code and in what scenarios are they used.
推荐答案
FileInputStream
extends InputStream
:它是一个专门版本的一个用于读取文件的InputStream。
FileInputStream
extends InputStream
: it is a specialized version of an InputStream designed for reading files.
根据使用它,有几种InputStream实现。
There are several implementations of an InputStream according to the use of it.
通常使用代码中所需的最高类型是一种好习惯。因此,如果您的代码需要从 InputStream
中读取数据,而不是从 FileInputStream
中读取数据,则应使用的InputStream
。然而,如果您确实需要保持对象的信息是 FileInputStream
而不仅仅是 InputStream
,那么你应该保持 FileInputStream
类型。
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.
这篇关于在创建FileInputStream对象时使用InputStream而不是FileInputStream有什么不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!