什么是InputStream&输出流?我们为何以及何时使用它们? [英] What is InputStream & Output Stream? Why and when do we use them?

查看:184
本文介绍了什么是InputStream&输出流?我们为何以及何时使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人向我解释 InputStream OutputStream 是什么?

Someone explain to me what InputStream and OutputStream are?

我对 InputStream OutputStream 的用例感到困惑。

I am confused about the use cases for both InputStream and OutputStream.

如果你还可以附上一段代码来附上你的解释,那就太好了。谢谢!

If you could also include a snippet of code to go along with your explanation, that would be great. Thanks!

推荐答案

InputStream OutputStream 用于抽象输入和输出的不同方式:流是文件,网页还是屏幕无关紧要。重要的是您从流中接收信息(或将信息发送到该流中。)

The goal of InputStream and OutputStream is to abstract different ways to input and output: whether the stream is a file, a web page, or the screen shouldn't matter. All that matters is that you receive information from the stream (or send information into that stream.)

InputStream 是用于你读取的很多东西。

InputStream is used for many things that you read from.

OutputStream 用于你写的很多东西。

OutputStream is used for many things that you write to.

这是一些示例代码。它假设已经创建了 InputStream instr OutputStream osstr

Here's some sample code. It assumes the InputStream instr and OutputStream osstr have already been created:

int i;

while ((i = instr.read()) != -1) {
    osstr.write(i);
}

instr.close();
osstr.close();

这篇关于什么是InputStream&输出流?我们为何以及何时使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆