java 流定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6327904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Stream definition
提问by xdevel2000
I'm reading on Java I/O streams and I'm confused on the correct definition associated with them.
我正在阅读 Java I/O 流,但对与它们相关的正确定义感到困惑。
- Some say that a stream is a sort of conveyor belt in which data are transmitted...
- other say that a stream is a flow or a sequence of a data...
- other say that a stream is a connection to an input or an output source...
- 有人说流是一种传送带,在其中传输数据......
- 换句话说,流是一个流或一个数据序列......
- 换句话说,流是到输入或输出源的连接......
So what's the correct definition?
那么正确的定义是什么?
回答by miku
A stream is a concept, but it's not that strict, that just only one description would be correct.
流是一个概念,但它没有那么严格,只有一种描述是正确的。
An I/O Stream representsan input source or an output destination. A stream can represent many different kinds of sources and destinations, including disk files, devices, other programs, and memory arrays. Streams supportmany different kinds of data, including simple bytes, primitive data types, localized characters, and objects. Some streams simply pass on data; others manipulate and transform the data in useful ways.
No matter how they work internally, all streams present the same simple model to programsthat use them: A stream is a sequence of data.
I/O Stream表示输入源或输出目的地。流可以表示许多不同类型的源和目标,包括磁盘文件、设备、其他程序和内存阵列。流支持许多不同类型的数据,包括简单字节、原始数据类型、本地化字符和对象。有些流只是简单地传递数据;其他人以有用的方式操作和转换数据。
无论它们在内部如何工作,所有流都向使用它们的程序呈现相同的简单模型:流是一个数据序列。
From: http://download.oracle.com/javase/tutorial/essential/io/streams.html
来自:http: //download.oracle.com/javase/tutorial/essential/io/streams.html
Also a stream is either an input stream or output stream. If it is an input stream, in Java it will adhere to the InputStream
interface, the latter to the Outputstream
.
同样,流是输入流或输出流。如果它是一个输入流,在 Java 中它将遵循InputStream
接口,后者遵循Outputstream
.
(Side note: In crypto, there's e.g. a difference between stream and block ciphers, where a streamcipher is something that does not know (in a very general sense) anything about the future, while a block cipher knows its (maximum) size in advance and the sizes of all coming blocks.)
(旁注:在加密中,流密码和块密码之间存在例如差异,其中流密码是不知道(在非常一般的意义上)任何关于未来的东西,而块密码知道它的(最大)大小前进和所有即将到来的块的大小。)
回答by Peter Lawrey
I would say a Stream is like all of these, but not exactly any of these.
我会说 Stream 就像所有这些,但不完全是这些。
I would say its an ordered sequence of 8-bit bytes.
我会说它是一个有序的 8 位字节序列。
回答by Koray Tugay
Java programs perform I/O through streams. A stream is an abstraction that either produces or consumes information. A stream is linked to a physical device by the Java I/O system. All streams behave in the same manner, even if the actual physical devices to which they are linked differ. Thus, the same I/O classes and methods can be applied to any type of device. This means that an input stream can abstract many different kinds of input: from a disk file, a keyboard, or a network socket. Likewise, an output stream may refer to the console, a disk file, or a network connection. Streams are a clean way to deal with input/output without having every part of your code understand the difference between a keyboard and a network, for example. Java implements streams within class hierarchies defined in the java.io package.
Java 程序通过流执行 I/O。流是产生或消费信息的抽象。Java I/O 系统将流链接到物理设备。所有流都以相同的方式运行,即使它们链接到的实际物理设备不同。因此,相同的 I/O 类和方法可以应用于任何类型的设备。这意味着输入流可以抽象出许多不同类型的输入:来自磁盘文件、键盘或网络套接字。同样,输出流可以指控制台、磁盘文件或网络连接。例如,流是一种处理输入/输出的干净方式,无需让代码的每个部分都了解键盘和网络之间的区别。Java 在 java.io 包中定义的类层次结构中实现流。
From: Java The Complete Reference
来自:Java 完整参考
回答by Rohit
In my viewpoint stream is actually a conveyor belt as you mention in the first point. Actually there are two types of stream, input, and output. An input stream is used to read the data from the input device like keywords and write that data to the files and output stream is used to read data from the disks, files, etc and write that data to the output device like console, monitor, etc.
在我看来,流实际上是您在第一点中提到的传送带。实际上有两种类型的流,输入和输出。输入流用于从输入设备(如关键字)读取数据并将该数据写入文件,输出流用于从磁盘、文件等读取数据并将该数据写入输出设备(如控制台、监视器、等等。
In a simple way, it is the bridge that helps to transport things from one point to another.
简单来说,它是帮助将物品从一个点运送到另一个点的桥梁。
回答by Adrian Liu
Just think it this way: Streams are objects that you can ask for pieces of data or send pieces of data to.
可以这样想:流是您可以请求数据片段或向其发送数据片段的对象。
回答by Sanjay Dhara
Java performs I/O throw streams. A stream is an abstraction that either produces or consumes information. A stream is linked to a physical device by the java I/O stream. Streams are a cleaned way to deal with input or output without having every part of code understand. Java defines two types of stream: byte and character
Java 执行 I/O 抛出流。流是产生或消费信息的抽象。流通过 java I/O 流链接到物理设备。流是一种处理输入或输出的干净方式,无需理解代码的每一部分。Java 定义了两种类型的流:字节和字符