Middle
Which class allows reading data from an input byte stream in primitive data types format?
sobes.tech AI
Answer from AI
DataInputStream.
It extends FilterInputStream and allows reading Java primitive data types (as defined by the DataInput interface) from a stream.
For example:
// Example of reading an integer value from a stream
try (DataInputStream dis = new DataInputStream(new FileInputStream("file.bin"))) {
int value = dis.readInt();
// Process the value
} catch (IOException e) {
e.printStackTrace();
}
Main methods for reading primitive types:
readBoolean()readByte()readChar()readDouble()readFloat()readInt()readLong()readShort()readUTF()(for UTF-8 formatted strings)
It provides a reliable way to serialize and deserialize primitive data.