- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadBytes.java
More file actions
Latest commit
19 lines (17 loc) · 620 Bytes
/
Copy pathReadBytes.java
File metadata and controls
19 lines (17 loc) · 620 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Add characters from stdin to an array
importjava.io.IOException;
classReadBytes {
publicstaticvoidmain (String[] args)
throwsIOException {
// WARNING: InputStream requires a byte array!
byte[] array = newbyte[10];
// prompt user for some characters to enter
System.out.print("Write some characters: ");
System.in.read(array);
System.out.print("The array fit: ");
for (byteb: array)
// cast to char mandatory - otherwise symbol ordinals are printed!
System.out.print((char) b);
System.out.println();
}
}