Sobes.tech
Junior — Middle

Kas saaksite selgitada, mis on andmesisendi voog?

sobes.tech AI

Vastus AI-lt

Input Stream in Java is an abstraction for sequentially reading bytes from a data source, such as a file, network, or other device. It allows reading data byte by byte or in blocks, without loading the entire content into memory at once.

Example of using InputStream to read a file:

import java.io.FileInputStream;
import java.io.InputStream;

public class Example {
    public static void main(String[] args) throws Exception {
        InputStream input = new FileInputStream("file.txt");
        int data = input.read(); // reads one byte
        while(data != -1) {
            System.out.print((char) data);
            data = input.read();
        }
        input.close();
    }
}

This way, the input stream allows sequential processing of data, which is especially useful when working with large files or network connections.