Files in Java – tccicomputercoaching.com
- August 21, 2019
- Posted by: Riddhi Dhandha
- Category: Java course at TCCI
Java I/O (Input and Output) is used to process the input and produce the output based on the input.
Java uses the concept of stream to make I/O operation fast. The java.io package contains all the classes required for input and output operations.
The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream in the java.io package supports many data such as primitives, object, localized characters, etc.
We can perform file handling in java by java IO API.
An I/O Stream represents an input source or an output destination. A stream can represent many different kinds of sources and destinations, includin disk files, devices, other programs, and memory arrays.
Streams support many 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 programs that use them: A stream is a sequence of data. A program uses an input stream to read data from a source, one item at a time: Reading information into a program.
A program uses an output stream to write data to a destination, one item at time:
Writing information from a program.
A stream is a sequence of data. In Java a stream is composed of bytes. It’s called a stream because it’s like a stream of water that continues to flow.
InPutStream − The InputStream is used to read data from a source.
OutPutStream − The OutputStream is used for writing data to a destination.
In java, 3 streams are created for us automatically. All these streams are attached with console.
1) System.out: standard output stream
2) System.in: standard input stream
3) System.err: standard error stream
Let’s see the code to print output and error message to the console.
Java encapsulates Stream under java.io package. They are
Byte Stream: It provides a convenient means for handling input and output of byte.
Character Stream: It provides a convenient means for handling input and output of characters. Character stream uses Unicode and therefore can be internationalized.
Java byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream.
Visit us @ https://tccicomputercoaching.com/
Call us @ 9825618292