package io;
import java.io.*;
import java.util.Scanner;
public class Exercise17_18 {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
System.out.print("Enter a file name: ");
File file = new File(input.nextLine().trim());
if (!file.exists())
System.out.println("No such file exists!");
else {
try(DataInputStream inputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(file)))) {
try {
while (true)
System.out.print(getBits(inputStream.readByte()) + " ");
} catch (EOFException ex) {
}
}
}
}
/** 返回整数的比特表示 */
public static String getBits(int value) {
String binary = Integer.toBinaryString(value);
return binary.substring(binary.length() >= 8 ? binary.length()-8 : 0);
}
}