1 // BinaryDump.java
2
3 import java.io.InputStream;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6
7 /** 8 * BinaryDump gibt den Inhalt einer Datei byte-weise binär aus. 9 * @author H.Drachenfels 10 * @version 10.1.2019 11 */
12 public final class BinaryDump {
13 private BinaryDump() { }
14
15 /** 16 * @param args optional ein Dateiname 17 * @throws IOException bei Lesefehlern 18 */
19 public static void main(String[] args) throws IOException {
20 InputStream in;
21
22 if (args.length == 0) {
23 in = System.in;
24 } else {
25 in = new FileInputStream(args[0]);
26 }
27
28 int b;
29 int i = -1;
30 while ((b = in.read()) != -1) {
31 if (++i % 8 == 0) {
32 System.out.println();
33 }
34
35 System.out.printf(
36 " %08d", Integer.parseInt(Integer.toBinaryString(b)));
37 }
38
39 System.out.println();
40 }
41 }
42