I am writing the code for the first time in new employee training at work. I think streams are a very basic thing, I can't help but find out what I didn't understand.
Stream is "flow" in Japanese. I feel that the word "data flow" often appears in sentences that describe streams. But when I say "flow", it doesn't come to my mind.
In the field of programming, it often means an abstract object or data type that handles data input / output in general. It is an abstraction that allows you to handle some object (memory area, file, network, etc.) in which data enters and exits in the program, and you can connect, disconnect, write, and read with simple operations.
Source e-words(http://e-words.jp/w/%E3%82%B9%E3%83%88%E3%83%AA%E3%83%BC%E3%83%A0.html)
Does it mean something like "a program that can handle the area where data goes in and out"?
So how do you handle streams in Java?
All Java I / O features are designed around the concept of "streams", which represent the flow of characters and byte sequences. In Java, streams are a standardized mechanism for reading and writing data, and all objects in Java that represent variable data sources provide methods for reading and writing data as streams.
Source builder(https://builder.japan.zdnet.com/java/20363416/)
Oh, when all I / O processing is done in streams in Java ...
Classes that handle stream-oriented I / O are often included in the java.io package. At the heart of this package are two abstract classes, the InputStream class and the OutputStream class. All other stream-oriented classes are defined as extensions of these classes.
Source Same as above
I see. As illustrated on the original site, The FileReader class also inherits the InputStream class. So, if you use it, you will be using a stream.
java.io.FileReader fileReader = new java.io.FileReader("/home/me/myfile.txt");
int aChar = 0;
while ((aChar = fileReader.read()) >= 0){
System.out.println((char)aChar);
}
So what's the difference between using a stream and not using it? The question arises, but I will come back to that later. .. ..
Recommended Posts