Input/Output in Java
Author: Ravi Poswal
In java, treat the flow of data as stream based. A collection of bytes is represented as a stream. A stream is carrying out input/output actions. You can say that stream is like a pipe in which data is a transfer from source to destination.
Advance I/O streams following characteristics
-
Abstraction
-
Flexibility
-
High Speed
Java provides java.io package, which contains many stream classes. Input/Output stream provides two ways
-
Byte Oriented: The flow of data handling on bytes
-
Character Oriented: The flow of data handles characters
Above, both stream ways are different from each other. Character-oriented stream support Unicode characters but byte oriented do not support them.
Code Example
class Test {
public static void main(String[] args) {
byte[] data = {65, 66, 67, 68, 69}; // byte array
for (int i = 0; i < data.length; i++) {
System.out.println("Byte value: " + data[i] + " Character: " + (char)data[i]);
}
}
}
RANREV INFOTECH