InputStream Reading Methods:
Using System.in for Reading:
Reading Console Input: System.in is used as input stream, where pressing "ENTER" indicates the end of the input stream.
ReadBytes Code Example:
Functionality: The program reads a byte array from the console and displays the entered characters.
Code Structure:
data[]: 10-byte array to store the input.
System.in.read(data): Reads the characters typed into the console and stores them in data.
Display Loop: Iterates over data[] to convert each byte to character and display them.
Example Code:
import java.io.*; class ReadBytes { public static void main(String args[]) throws IOException { byte data[] = new byte[10]; System.out.println("Enter some characters."); System.in.read(data); // Lê o array de bytes System.out.print("You entered: "); for (int i = 0; iExecution Example:
Input: "Read Bytes"
Exit:Enter some characters. You entered: Read BytesThis excerpt details how to use the read() methods to read data from the keyboard in byte format, illustrating the basic use of System.in for console input and demonstrating direct manipulation of bytes in an array.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3